Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Wiki Markup
{iframe:src=http://update.sonarsource.org/plugins/switchoffviolations.html|width=700|height=250|frameborder=0}
Your browser does not support iframes.
{iframe}
Warning
titleDeprecated since SonarQube 4.0

The features provided by the Switch Off Violations plugin were added to SonarQube 4.0 and extended. Therefore, this plugin must not be used anymore with SonarQube 4.0+.

Description / Features

This plugin is used to exclude some issues in a fine-grained way. It allows to define some exclusion patterns to switch off issues:

  • By rule
  • By file name/path
  • By line or range of lines
  • By file content

Include Page
Include - Plugin Installation
Include - Plugin Installation

Configuration

Exclusion patterns can be specified at both global and project levels. Go to Settings > Configuration > General Settings > Switch Off Violations (or at project level: Configuration > Settings > Switch Off Violations) and add exclusion patterns to the following properties:

  • File exclusion patterns (sonar.switchoffviolations.allfile) to switch off all the issues on files that contain a block of code that matches a given regular expression.
    • Example: switch off all the issues on files containing @javax.annotation.Generated
  • Bloc exclusion patterns (sonar.switchoffviolations.block) to switch off issues 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-FIRST and GEN-LAST (like NetBeans auto-generated code):
  • Multi-criteria exclusion patterns (sonar.switchoffviolations.multicriteria) to switch off issues on specific resources, rules and ranges of lines.
    • Examples: 
      • Switch off all the issues (Java projects: structure = packages) => *;*;*
      • Switch off all the issues (non-Java projects: structure = folders) => **/*;*;*
      • Exclude all the issues on the Java file com.foo.Bar => com.foo.Bar;*;*
      • Exclude all the issues on the Java package com.foo => com.foo.*;*;*
      • Exclude all the issues of a specific rule => *;checkstyle:com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck;*
      • Exclude all the issues of a specific rule on a specific file => com.foo.Bar;checkstyle:com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck;*
      • Exclude all the issues on specific lines 10, 25 and 90 => com.foo.Bar;*;[10,25,90]
      • Exclude all the issues on a range of lines => com.foo.Bar;*;[10-90]
      • Exclude all the issues on several ranges of lines => com.foo.Bar;*;[10-90,92,98,120-150]
         
Info
titleVersions prior to 1.3

Set the sonar.switchoffviolations.patterns property:

Code Block
titleExamples
languagenone
# Switch off all issues (Java projects: structure = packages)
*;*;*

# Exclude a specific rule
*;checkstyle:com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck;*

# Exclude on several ranges of lines
com.foo.Bar;*;[10-90,92,98,120-150]
 
# Exclude code blocks delimited by GEN-FIRST and GEN-LAST (like NetBeans auto-generated code)
GEN-FIRST;GEN-LAST
 
# Exclude files containing "@javax.annotation.Generated"
@javax\.annotation\.Generated

Usage

Run an analysis on your project to take into account your configuration.

Change Log

JIRA Issues
anonymoustrue
titleRelease 1.3
renderModestatic
width900
columnstype;key;summary;priority
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+SONARPLUGINS+AND+fixVersion+%3D+%22SWITCH-OFF-VIOLATIONS-1.3%22+ORDER+BY+priority+DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleRelease 1.2
renderModestatic
width900
columnstype;key;summary;priority
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+SONARPLUGINS+AND+fixVersion+%3D+%22SWITCH-OFF-VIOLATIONS-1.2%22+ORDER+BY+priority+DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleRelease 1.1
renderModestatic
width900
columnstype;key;summary;priority
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+SONARPLUGINS+AND+fixVersion+%3D+%22SWITCH-OFF-VIOLATIONS-1.1%22+ORDER+BY+priority+DESC&tempMax=1000