How to avoid 'Add headers to table' warning

Operating system: Windows 11
SonarLint plugin version: SonarLint for Eclipse 7.4.0.46482

Please I need help on how to avoid warnings about missing TH tag. Includes that I mention does have TR, TH and TD elements, but this is visible after compile time, of course.

Multiple annotations found at this line:
Add <th> headers to this <table>
Start tag of element <table>

Code snippet that triggers warnings:

<table class="EditTable">
    <caption th:text="#{ captions.TableCaption }"></caption>
    <th:block th:insert="/modules/photos.html" />
    <th:block th:insert="/modules/address.html"/>
    <th:block th:insert="/modules/phoneEmailUrl.html"/>
    <th:block th:insert="/modules/objectStatusDropdown.html" />
    <th:block th:insert="/modules/dateCreatedLastUpdated.html" />
</table>

The problem is I have more than one table and not each table is having all includes. Some tables have only address, some tables have other includes not mentioned here. Duplicating code by copy/pasting incude contents is not an option because there are more than 15 different tables with many includes.

Hey @H.Lo,

thank you very much for bringing this to our attention.

Raising this issue here is indeed wrong, and we should fix that in the analyzer. I’ve created a ticket to have this tracked [SONARHTML-161] - Jira.

In the meantime, to avoid getting this wrong warnings you can either:

  • Deactivate the rule. This might make sense if you make extensive use of such inclusions throughout your codebase.
  • Suppress issues on those tables by adding a //NOSONAR beside the table opening tag. Example: <table class="EditTable"> <!-- //NOSONAR -->
2 Likes

Thanks!
Your advice did the job. I only added comment marks inside comment marks inside your solution to avoid showing up in final HTML (renderey by thymeleaf):

<!--/* //NOSONAR */-->
1 Like