5

I'm trying to ignore Lombok code (generated code) from Sonar analysis based on files which have a custom annotation, @ExcludeLombok. I've tried this guide which did not work.

In fact, I've even tried excluding an entire directory from analysis and it still wouldn't work.

I've also tirelessly searched through StackOverflow looking for a solution, and I've seen this has been discussed a good bit on here, but I've seen that people have been suggesting to write a single test to get the coverage up, which is pointless since we should not test auto generated code.

The solution I'm looking for is to exclude files based on a custom annotation. But so far, anything I attempt to exclude does not get excluded.

Any help would be greatly appreciated.

JJD
  • 50,076
  • 60
  • 203
  • 339
Paul Connolly
  • 53
  • 1
  • 3

2 Answers2

5

There is currently no easy way to exclude issues raised by the SonarQube rules from the SonarQube Java Analyzer, except from using approaches described in the "Narrowing the focus" documentation you quote.

Now, we introduced recently the concept of issue filters in the SonarQube Java Analyzer. This mechanism is at the moment only used internally to exclude issues raised by rules at analysis time, based on specific criteria.

We plan to extends this mechanism in order to allow users to implements their own custom issue filters, the same way custom rules can be implemented. This approach would cover your case and allow you to filter any rules on code annotated with your custom annotation. This new feature will be handled in the following JIRA ticket: SONARJAVA-1761

Wohops
  • 3,071
  • 18
  • 29
  • Please refer to JIRA ticket [SONARJAVA-1761](https://jira.sonarsource.com/browse/SONARJAVA-1761) for resolution of the issue. The ticket is currently planned for 5.x of the SonarJava analyzer. We are currently working on version 4.8. Version 5.x will be our next major release, but it is not expected before this summer. – Wohops Mar 22 '17 at 08:49
  • 1
    @Michael-SonarSourceTeam It seems like the filter mechanism does exist now and there is a LombokFilter in the code at : https://github.com/SonarSource/sonar-java/tree/master/java-checks/src/main/java/org/sonar/java/filters But with Sonar 6.3 still the lombok issues are not filtered. – Chris May 26 '17 at 06:14
  • @Michael-SonarSourceTeam Can you please state what is the current state? From **which Sonar version** Lombok is **fully** supported? – JJD Jun 15 '17 at 16:07
  • 1
    @JJD why do you mean by "Lombok being fully supported"? We do **not** support Lombok, some rules are simply reacting accordingly to the recognized annotations, but requires bytecode do be correctly provided for the analysis. There is also, indeed, a filter which have been implemented in version 3.14 of SonarJava plugin [SONARJAVA-1642](https://jira.sonarsource.com/browse/SONARJAVA-1642), and updated later (SonarJava 4.5 and 4.8), to exclude **some** FPs related to usage of lombok annotations. Please check which version of SoanrJava plugin is installed in your SQ instance. – Wohops Jun 16 '17 at 14:06
0

Another option you have is to run Sonar over delomboked source. There are various ways to delombok depending on your build system see: Delombok Overview.

For maven there's an example of running analysis on delomboked code: Delombok test pom

In each case you would make sure you ran the checks over generated source.

andygavin
  • 2,784
  • 22
  • 32