In sonar rules, there is a S00107 rule for "Methods should not have too many parameters". This rule has exceptions for some annotations:
Exceptions
Methods annotated with Spring's @RequestMapping (and related shortcut annotations, like @GetRequest) or @JsonCreator may have a lot of parameters, encapsulation being possible. Such methods are therefore ignored.
Is it possible to add another annotations to this exceptions?
My case: I have constructors, annotated by the Lombok's @Builder
, which contains a lot of parameters! So i want to ignore this rule on these constructors.
public class MyClass extends MySupperClass {
@Builder
public MyClass(String a, int b, ..., String z) {
}
}
Using a builder can solve the issue of having to many parameters in a constructor when all the fields are not mandatory. It also takes away the problems with having multiple constructors for different purposes. Note that a builder still should have a constructor with the mandatory fields that always needs to be set.
The number of method parameters is limited to 255 by the definition of a method descriptor (§4.3. 3), where the limit includes one unit for this in the case of instance or interface method invocations. Section §4.3.
Create a SonarQube plugin. Put a dependency on the API of the language plugin for which you are writing coding rules. Create as many custom rules as required. Generate the SonarQube plugin (jar file). Place this jar file in the SONARQUBE_HOME/extensions/plugins directory. Restart SonarQube server.
In sonar rules, there is a S00107 rule for " Methods should not have too many parameters ". This rule has exceptions for some annotations: Methods annotated with Spring's @RequestMapping (and related shortcut annotations, like @GetRequest) or @JsonCreator may have a lot of parameters, encapsulation being possible.
The Java API will be more fully-featured than what's available for XPath, and is generally preferable. However, this comes with the overhead of maintaining a SonarQube plugin (including keeping it up-to-date as APIs change, upgrading the plugin after releasing a new version).
This rule has exceptions for some annotations: Methods annotated with Spring's @RequestMapping (and related shortcut annotations, like @GetRequest) or @JsonCreator may have a lot of parameters, encapsulation being possible. Such methods are therefore ignored. Is it possible to add another annotations to this exceptions?
Try to add @SuppressWarnings("squid:S00107")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With