...
Exclusion patterns can be specified at both global and project levels. Go to Configuration > General Settings > Switch Off Violations (or at project level: Configuration > Settings > Switch Off Violations) and set the 'add values to the following properties:
- File exclusion patterns (
sonar.switchoffviolations.
...
- A line can have the following formats:
- A semi-colon separated string defining 3 parts: resource key pattern, rule key pattern and range of lines.
- A semi-colon separated string defining 2 parts: a first regular expression and a second one, which will be used to determine blocks of code for which violations must be ignored
- Note: if the first regular expression is found but not the second one, then the plugin considers that the end of the code block is the end of the file.
- A single string defining a regular expression which will be used to determine files that should be ignored if they match this regular expression
- Comments start with #
- Blank lines are allowed
...
| title | Examples |
|---|---|
| language | none |
...
allfile) to switch off all the violations on files that contains a block of code that matches a given regular expression.- Example: switch off all the violations on files containing
@javax\.annotation\.Generated
- Example: switch off all the violations on files containing
- Multi-criteria exclusion patterns (
sonar.switchoffviolations.multicriteria) to switch off violations on specific resources, rules and ranges of lines.- Examples:
- Switch off all the violations (Java projects: structure = packages) =>
*;*;* - Switch off all the violations (non-Java projects: structure = folders) =>
**/*;*;*
- Switch off all the violations (Java projects: structure = packages) =>
- Examples:
...
- Exclude all the violations on the Java file
com.foo.Bar
- Exclude all the violations on the Java file
...
- =>
com.foo.Bar;*;*
- =>
...
- Exclude all the violations on the Java package
com.foo=>com.foo.*;*;*
- Exclude all the violations on the Java package
...
- Exclude all the violations of a specific rule =>
*;checkstyle:com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck;*
- Exclude all the violations of a specific rule =>
...
- Exclude all the violations of a specific rule on a specific file =>
com.foo.Bar;checkstyle:com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck;*
- Exclude all the violations of a specific rule on a specific file =>
...
- Exclude all the violations on specific lines 10, 25 and 90 =>
com.foo.Bar;*;[10,25,90]
- Exclude all the violations on specific lines 10, 25 and 90 =>
...
- Exclude all the violations on a range of lines =>
com.foo.Bar;*;[10-90] - Exclude all the violations on several ranges of lines =>
com.foo.Bar;*;[10-90,92,98,120-150]

- Exclude all the violations on a range of lines =>
- Bloc exclusion patterns (
sonar.switchoffviolations.block) to switch off violations on specific blocks of code. Note: if the first regular expression is found but not the second one, then the plugin considers that the end of the code block is the end of the file.- Example: exclude code blocks delimited by
GEN-FIRSTandGEN-LAST(like NetBeans auto-generated code):
- Example: exclude code blocks delimited by
| Info | |||||||
|---|---|---|---|---|---|---|---|
| |||||||
Set the
|
Usage
Run a Sonar analysis on your project to take into account your configuration.
...

