Help needed: How does NOSONAR comment work in .js/.ts files?

I need some help. How does the NOSONAR comment work in .js / .ts files?

I have a piece of code where I don’t want to disable the entire rule in the ESLint config. I found some information about NOSONAR, but it’s unclear how exactly the comment should be written to make it ignore this specific usage.

/eleventy.config.js
  81:10  error  Make sure disabling auto-escaping feature is safe here  sonarjs/disabled-auto-escaping

This is also strange, because when I enable the no-sonar-comments rule, it starts complaining about this very comment.

Maybe there’s already a topic about this somewhere, but I couldn’t find it.
Sorry in advance if I missed it, I’m new here :folded_hands:

Hey there.

NOSONAR must go on the exact line an issue is raised. It looks like you’re putting it on the line above!

That said, since you’re using the ESLint plugin, you may need to use // eslint-disable-line instead (I haven’t tested this)

Hey Colin! Something like this?

Unfortunately, I’m still getting the error…

In general, I can disable rules using eslint-disable, but I found it interesting to try using NOSONAR instead.
Also, if rules can’t be disabled with NOSONAR comments, then I’m curious – why does this no-sonar-comments rule even exist in the ESLint plugin?
https://www.npmjs.com/package/eslint-plugin-sonarjs?activeTab=readme#:~:text=%E2%9C%85-,no%2Dsonar%2Dcomments,-Track%20uses%20of

It should be at the end of the line.

let md = markdownIt({ //NOSONAR
html:true
})

Unfortunately, it still doesn’t work :smiling_face_with_tear:

Hello @what1s1ove,

// NOSONAR comments are only silencing issues in Sonarqube. They are not applicable in Eslint context.

The rule about no-sonar-comments is to be used if an admin would like to forbid the usage of such comments in their codebase.

In Eslint context, we recommend using the eslint directives.

Cheers!

Hey Victor! Got it! Thank you for the answer!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.