5

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

Community
  • 1
  • 1
computnik
  • 287
  • 1
  • 3
  • 15

3 Answers3

6

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

Rafal Wiliński
  • 2,240
  • 1
  • 21
  • 26
  • 8
    Apologies for such delay. `// NOSONAR` works for a single line, is there something for a block of code? like a function, or if-else-if block. – computnik Feb 27 '17 at 04:28
4

SonarQube provides plenty of options for ignoring issues in specific files and/or code blocks, see Narrowing the Focus documentation (and to your specific case: look for Ignore Issues in Blocks).

Jan P
  • 786
  • 6
  • 27
Nicolas B.
  • 7,245
  • 17
  • 29
1

To ignore blocks:

 // BEGIN-NOSCAN
const YourFunction () => {
  // Your code
}
 // END-NOSCAN

To ignore single lines:

// NOSONAR
const YourCode = 'Example';

You can read more about it here in the SonarQube docs Narrowing the Focus. Thanks to Jan and Nicolas's answer above.

Ian
  • 1,746
  • 1
  • 15
  • 28