Web:ItemTagNotWithinContainerTagCheck - ul and li tags within repeater in asp.net framework

SonarQube
Enterprise Edition
Version 9.4 (build 54424)

In my asp.net framework 4.8 project, I have an aspx file with code similar to the following:

<asp:Repeater ID="TestRepeater" runat="server">
	<HeaderTemplate>
		<ul>
	</HeaderTemplate>
	<FooterTemplate>
		</ul>
	</FooterTemplate>
	<ItemTemplate>
		<li>Test</li>
	</ItemTemplate>
</asp:Repeater>

This code reports a BUG with the following rule:

Web:ItemTagNotWithinContainerTagCheck
"<li>" and "<dt>" item tags should be in "<ul>", "<ol>" or "<dl>" container tags

The output for this code above with 3 repeateritems would look like the following:

<ul>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
</ul>

I believe this to be a false positive because in the example above, when the code renders my page, the ul tag in the header template will be rendered first and then the repeating item template will render the li tags (for however many repeateritems I have) and lastly the closing ul tage from the footer template. The output will be syntactically correct and wont break this rule.

1 Like

I have encountered a couple similar problems with this rule in similar contexts:

1 - Razor (.cshtml) layout

This rule gets triggered in the following case:

In a layout page:

<ul>
@RenderSection("tabs")
</ul>

In a .cshtml page using said layout:

@section tabs {
<li>Tab heading</li>
}

Once composed the page is correctly structured, but Sonar cannot know this and reports an error.

2 - template HTML tag

The template HTML tag should be able to contain any other tag, since it too can be used for dynamic composition.
In particular we use Aurelia (v1) which mandates the template tag for its components.

This snippet triggers the rule:

<template>
    <li>A list element, which should be more complex than this example.</li>
</template>