sonar-findbugs
sonar-findbugs copied to clipboard
Apply fb-contrib rules to Unit Tests
In fact since Sonar 3.1 SONAR-1076, everything is in place to be able to report and display a violation on a unit test source file. But it's still the responsibility of each rule engine to decide which rule must be applied to a unit test source file or not.
I don't see how this is can be done. 🤔
We are using JavaResourceLocator to obtains the classes in the scope.
https://github.com/spotbugs/sonar-findbugs/blob/master/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java#L82
If JavaResourceLocator is able to return test classes, this should work transparently.
Aside from blindly looking for test classes, I don't see an API that would return those.
@ganncamp Maybe I am missing something?
@h3xstream I have no memory of this :grinning:
However I do know that the SonarJava analyzer makes a distinction between which rules are applied to source files and which to test files. I can't tell you off-hand how, but I'm sure you could that that info on the Google Group.
Thanks, @ganncamp for the response.
I was unsure if sonar-java was getting only the test sources files or also at the binaries. I did a quick search and found that sonar-java did both. (at first glance) https://github.com/SonarSource/sonar-java/blob/0d545786c262e5ec0aa4e14f0763ef98ec670c37/java-frontend/src/main/java/org/sonar/java/JavaTestClasspath.java#L46-L51
This should be fixed in version 4.2.3 (just released) Note that the fix needs the SonarQube version to be >= 9.8