SonarQube Cloud, SonarQube Server, or SonarQube Community Build? (if one of the latter two, which version?): No
And a thorough description of the problem / question:
We have a lot of generated code (we use a lot of Eclipse EMF) and we would like to exclude such generated code from Sirius analysis.
It should be noted that having a suffix like: @generated NOT tells it that the code has been customized, and thus we would want Sonar to apply to such code.
Is there a facility where a custom regex or something can be applied ? We can’t force it to add a //NOSONAR to every such method.
Generated code should be automatically marked as such, but that typically relies on @Generated actually being marked on the method (like @Override), not in the Javadoc. Do you know why it’s in the Javadoc in this case?
From what I gather this is pretty specific to Eclipse EMF (the javadoc-based @Generated annotation). I’m not sure that’s something we want to build into the analyzer (I’m happy to send along the feedback).
With SonarQube, it is possible to Ignore Blocks Within Files, and – say, start ignoring code when you see a @generated tag, and stop when you get to @generated NOT. Is that something that could work for you?
You could share this configuration across the team by configuring it in a SonarQube project and using Connected Mode.
This would, however, rely on a perfect ordering of the code (all added code at the top, as shown in the screenshot you shared).
Unfortunately that wouldn’t work. We have no real control on the order of the code and even if we did that would very brittle.
I would really have hoped for an API or a way to use a regex that receives the full method including its javadoc and return a boolean to indicate go/no-go. We have done this in one of our code analysis project a long time ago.