How make java custom rules on sonarqube?

Hello! We have been investigating and testing with SonarQube to try to adapt some rules that are making “isuess” jump in the revision that is made with Cast in our maven project. For some we have managed to locate their equivalents in Sonar, but for others we haven’t, so we are trying to create custom rules. We have made the example rule that appears in Custom Rules 101, but we have not found more information to make the following rule:

  • Avoid using Fields (non static final) from other Classes

Greetings and thank you

Heye there.

If somebody had already documented how to write such a rule, there wouldn’t be much point in writing it yourself, would there? :wink:

That said, I think you are looking for a rule that already exists in some form: S1104: Class variable fields should not have public accessibility raising issues on class fields that have public accessibility, (rather than the use of those fields).

This rule is enabled by default in the built-in Sonar Way quality profile.

1 Like

Thank you! I’ll use that rule, what rules I can use for the next issues?

  • Avoid instantiations inside loops