3

I want to apply different SonarQube rules for production and test code.

For example: squid : S1192: "String literals should not be duplicated". It is quite reasonable in production but for test code is very annoying and can make it less readable.

I see how to deactive the rule but I can only disable it globally. At the same time I do not want to avoid analysing the whole test set.

2
  • 1
    docs.sonarqube.org/latest/project-administration/… says "exclude files/directories from Issues detection (specific rules or all of them) but analyze all other aspects" and gives details. does that not work ? Nov 6, 2019 at 22:38
  • 1
    @MichaelDurrant: Please post as an answer. You deserve the reputation bonus
    – borjab
    Nov 7, 2019 at 9:24

2 Answers 2

4

You can do this in Administration -> Configuration -> Analysis Scope -> Restrict Scope of Coding Rules. You need to specify the code of the rule (without spaces) and a file path pattern to filter. If you use the maven standard **/src/main/** will work for you.

enter image description here

For more information see the docs where it states that you can:

...exclude files/directories from Issues detection (specific rules or all of them) but analyze all other aspects" and gives details.

0

You can only suppress warnings at the project level, as you said, and at the file/method level. For file/method, it will depend on your language. In Java, you would add an annotation such as:

@java.lang.SuppressWarnings("squid:S1192") 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.