Exclude rules from unit tests?

I’m using SQ 7.3. In general, I agree with the No Magic Numbers rule (S109), but I’m not convinced it’s helpful in Unit Tests where literals are likely more readable than constants. Is there a way to disable a rule like this for a given source path (e.g. rule is enabled for src/main/java and disabled for src/test/java)?

I know we could use //SONAR for each one, but that’s potentially a lot of work.

See this discussion where the top two answers seem to agree:
https://softwareengineering.stackexchange.com/questions/384729/should-linters-no-magic-numbers-rule-used-in-testing

What it the configuration of your project? Do you execute SonarScanner for Maven or other version?

I use Maven 3 to execute the scanner. Is there a good way to have different rules for the testSource? I don’t want to skip SQ entirely for unit tests I don’t think.

It is impossible. I think this thread should be interesting for you:

1 Like