Activating custom rules to replace one causing false positives

We are experiencing false positives from ItemTagNotWithinContainerTagCheck from templates (in a framework).
The issue is similar to Ruby HTML views partials <li> issues - #4 by alban.auzeill
There is a corresponding ticket from October 2022 here [SONARHTML-159] - Jira

Seeing this might take some time we want to disable the ItemTagNotWithinContainerTagCheck rule and add a custom one.

For a custom rule we tried using ‘Track lack of required parent elements’:
But this rule only seems to apply to a single parent (cannot find documentation on comma- or space delimited input value).
Is this correct?

We also tried the custom rule ‘Track breaches of an XPath rule’ with which ItemTagNotWithinContainerTagCheck can be implemented and extended just fine. However, the rule applies to XML and cannot be activated in our custom HTML quality profile (where we are able to activate the a custom instance of ‘Track lack of required parent elements’).

Also, when creating a custom rule, is there an easy way to test it?

kind regards


Hey there.

SonarQube doesn’t offer an API for writing custom HTML rules, nor any template rules you can apply to HTML code.

If you write a tool that outputs results to Generic Issue Data, you might be in business.

Can you give an example of some code that you expect to have no issue on, but where one is being raised?

Hi Colin,

Thanks for replying and sorry for the holiday-seasons-delay.

It is an Angular codebase with an implementation like this:

    <li app-carousel-item>Carousel Item</li>

When rendered this will turn into <app-carousel><ul><li>Carousel Item</li></ul></app-carousel>.

(I’ll have a look at ‘generic issue data’, but writing a custom tool sounds like overkill. It might be easier to change the implementation itself.)