问题
I have a scenario where there is an AEM template file and in this file, I have a single <li>
element. In other words, I have a loop inside that generate a list of items.
<template data-sly-template.step>
<li
data-sly-use.localStep="MyAdapter"
data-sly-test="${(wcmmode.edit && localStep.start) || !wcmmode.edit}"
But, the Sonar's rule RSPEC-1093 is complaining that:
"<li>"
and"<dt>"
item tags should be in"<ul>"
,"<ol>"
or"<dl>"
container tags.
In this case, is not a bug, once that the <ul>
is outside of the template. The output file is a well-generated HTML file with no errors.
I'm trying to use NOSONAR
in html file. I have tried <!-- NOSONAR -->
and <!-- //NOSONAR -->
, but is not working.
How can I mark this line in HTML file to be ignored by sonar rules?
回答1:
I checked the SonarHTML plugin source code and for my understanding you have to add //NOSONAR
at the line which should be ignored. In your case it should be:
<template data-sly-template.step>
<!-- //NOSONAR --><li
data-sly-use.localStep="MyAdapter"
data-sly-test="${(wcmmode.edit && localStep.start) || !wcmmode.edit}"
If you compress the source code then the solution is safe to use. If not, you have to be aware that all those <!-- //NOSONAR -->
will be send to your client. It means that the resources usage will be bigger (for example network bandwidth - more bytes to send).
The //NOSONAR
is handled by org.sonar.plugins.html.visitor.NoSonarScanner
:
- source code
- test class
来源:https://stackoverflow.com/questions/58682506/how-can-i-mark-this-line-in-html-file-to-be-ignored-by-sonar-rules