SonarQube Plugins
  1. SonarQube Plugins
  2. SONARPLUGINS-1104

Add a way to exclude files from analysis based on file content

    Details

    • Number of attachments :
      0

      Description

      I saw the description for the upcoming 'switch off violations' plugin (http://docs.codehaus.org/display/SONAR/Switch+Off+Violations+Plugin). It would be nice to have a dynamic way of excluding files or suppress violations based on file content.

      We have several projects containing a lot of generated code which we would like to exclude from analysis. Since the code is generated from models, "static" exclude patterns with given package or file patterns are not helpful: file and package names can change from release to release for a given project / file and package names are different from project to project using the generator. It would be therefore nice to be able to specify a "content marker" instead of a file / package name pattern to exclude a file (e. g. exclude file from analysis if it contains '@generated' in the header).

      I'm not sure if this should be a feature for sonar itself or for the "switch off violations plugin". As far as I understand, the purpose of the 'switch off plugin' is the suppression of violations. However, in our case, excluding files altogether effectively removing them from any metric would be preferable.

        Issue Links

          Activity

          Hide
          Momin Khan added a comment -

          Exclusion of specific violations based on the content in a file is the feature i am looking for.
          I don't want to end-up setting each and every unwanted violation as a 'false positive'. Looking for a global content patttern matcher exclusion filter to switch off violation lets say 'unused private field' for specific instances in old java code which cannot be changed now (we have some constants auto-generated by the templated during the initial creation of the file years ago, and there are hundreds of them)

          Can we have 'content based regex' filter for the switchoff violations plugin?

          Show
          Momin Khan added a comment - Exclusion of specific violations based on the content in a file is the feature i am looking for. I don't want to end-up setting each and every unwanted violation as a 'false positive'. Looking for a global content patttern matcher exclusion filter to switch off violation lets say 'unused private field' for specific instances in old java code which cannot be changed now (we have some constants auto-generated by the templated during the initial creation of the file years ago, and there are hundreds of them) Can we have 'content based regex' filter for the switchoff violations plugin?
          Hide
          Freddy Mallet added a comment -

          Indeed Momin, this would be the goal to define two regular expressions in order to define the limits of the blocks to be be excluded.

          Show
          Freddy Mallet added a comment - Indeed Momin, this would be the goal to define two regular expressions in order to define the limits of the blocks to be be excluded.
          Hide
          Momin Khan added a comment -

          Awesome. Eagerly looking forward to this feature.
          SONAR team rocks
          Keep up the good work.

          Show
          Momin Khan added a comment - Awesome. Eagerly looking forward to this feature. SONAR team rocks Keep up the good work.
          Hide
          Fabrice Bellingard added a comment -

          ITs added.

          Show
          Fabrice Bellingard added a comment - ITs added.
          Hide
          Aaron Digulla added a comment -

          Can you please add support for the @javax.annotation.Generated annotation, too?

          It would be sufficient if I could simple ignore all files with this annotation completely. Even greater would be an option to specify a list of packages to ignore.

          Show
          Aaron Digulla added a comment - Can you please add support for the @javax.annotation.Generated annotation, too? It would be sufficient if I could simple ignore all files with this annotation completely. Even greater would be an option to specify a list of packages to ignore.
          Hide
          Freddy Mallet added a comment -

          @Fabrice, could you quickly describe how to use this new feature ?

          Show
          Freddy Mallet added a comment - @Fabrice, could you quickly describe how to use this new feature ?
          Hide
          Fabrice Bellingard added a comment -

          The existing pattern was a semi-colon separated string defining 3 parts (resource/violation/line range), like:

          org.foo.*;pmd:*;[12-56]
          

          Now, you can add:

          • a semi-colon separated string defining 2 parts, a first regexp and a second one, which define delimiters of blocks to ignore violations, like:
          SONAR-OFF;SONAR-ON
          
          • a single string that defines a regexp to exclude a whole file if this regexp is found, like:
          @auto-generated-file
          
          Show
          Fabrice Bellingard added a comment - The existing pattern was a semi-colon separated string defining 3 parts (resource/violation/line range), like: org.foo.*;pmd:*;[12-56] Now, you can add: a semi-colon separated string defining 2 parts, a first regexp and a second one, which define delimiters of blocks to ignore violations, like: SONAR-OFF;SONAR-ON a single string that defines a regexp to exclude a whole file if this regexp is found, like: @auto-generated-file
          Hide
          Freddy Mallet added a comment -

          Well done Fabrice, tested both with JAVA and COBOL projects !

          Show
          Freddy Mallet added a comment - Well done Fabrice, tested both with JAVA and COBOL projects !
          Hide
          Fabrice Bellingard added a comment -

          ITs added.

          Show
          Fabrice Bellingard added a comment - ITs added.

            People

            • Assignee:
              Fabrice Bellingard
              Reporter:
              Myster Mask
            • Votes:
              4 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: