Angular issue "Surround this <li> item tag by a <ul> or <ol> container one"

  • SonarQube Version - 9.7.0 , Scanner - 4.7.0 Linux
  • how is SonarQube deployed: zip
  • Code scan of Angular HTML and TS files.
  • Setup is done and it’s working fine. However, it is showing issue “Surround this li item tag by a ul or ol” container issue for few HTML files though the code is right.
    In an Angular HTML, ul is added and based on container condition li is added as a template present in some other part.
  • Issue is I don’t want to add NOSONAR comment and want to fix this. Is there anything that can be done to make Sonar understand that it’s not a issue.

Code sample:

<ul #fileButtonWrapper><!-- {...props.fileButtonWrapper.direct} -->
            <li>
                <a #fileButton><!-- {...props.fileButton.direct} -->
                    <input [id]="id" type="file" 
                    (change)="setSelectedFileName(props, $event.currentTarget)" 
                    attr.rowno="{{index}}"
                    #BrowseButton delegateEvent [blurEvent]="blur" [focusEvent]="focus"/><!-- {...props.BrowseButton.direct} {...props.apzevents}   -->
                    Browse... <!--{"Browse..."}-->
                        </a>
              <ng-container [ngTemplateOutlet]="UploadButtons"></ng-container> <!--{UploadButton(props)}-->
            </li>
            <ng-container [ngTemplateOutlet]="SelectedFile"></ng-container> <!-- {SelectedFile(props)} -->
        </ul>




//<li> code present somewhere else in same file. 

<ng-template #SelectedFile>
    <ng-container *ngIf="props.UploadButtonRequired == 'Y'">
     <!-- //NOSONAR -->  <li>
            <span class="filevalue" id="selectedfiles">
                <svg aria-hidden="true" role="presentation" class="icon  px24">
                    <use attr.xlink:href="#"></use>
                </svg>
            </span>
        </li>
    </ng-container>
</ng-template>

Hi,

Welcome to the community!

Can you upgrade to the latest version, 10.0, and see if this is still replicable?

 
Ann

Hello Ann,

Even after upgrading to 10, it is still showing above as a code smell.

Regards,
Amruta Jegarkal

Hi Amruta,

Thanks for checking! I’ve flagged this for the experts.

 
Ann

1 Like

Hello Ann,

Was this issue considered, any chances of releasing this change?

Regards,
Amruta Jegarkal

Hi Amruta,

The wheels of justice turn slowly. And sometimes so do our experts.

 
:smiley:
Ann

Hello @amruta.jv,

Thanks for bringing this up. Sorry it took a while to answer.

I agree this is a false positive in the HTML analysis. I created an internal ticket to track it:
https://sonarsource.atlassian.net/browse/SONARHTML-172