I would like to disable a block of code(say a function) in a file for analysis by SonarQube... Any suggestions on how to do that..
I found something for java here --> Turning Sonar off for certain code
I would like to disable a block of code(say a function) in a file for analysis by SonarQube... Any suggestions on how to do that..
I found something for java here --> Turning Sonar off for certain code
As far as I know Sonar respects // NOSONAR tag for Java projects but it looks like that is also has been implemented for JS: https://jira.sonarsource.com/browse/SONARJS-294
// NOSONAR works for a single line, is there something for a block of code? like a function, or if-else-if block.To ignore blocks:
// BEGIN-NOSCAN const YourFunction () => { // Your code } // END-NOSCAN To ignore single lines:
const YourCode = 'Example'; // NOSONAR You can read more about it here in the SonarQube docs Narrowing the Focus. Thanks to Nicolas's answer above.
Add below configuration in your sonar properties file
sonar.issue.ignore.block=e1 sonar.issue.ignore.block.e1.beginBlockRegexp=NOSONAR_BEGIN sonar.issue.ignore.block.e1.endBlockRegexp=NOSONAR_END and use annotations like this to ignore a specific code block
//NOSONAR_BEGIN your code //NOSONAR_END this is compatible with the latest sonarQube versions i.e. 9.9+.
For more reference: https://docs.communityhealthtoolkit.org/contribute/code/static-analysis/#ignoring-all-rules-for-a-block-of-code