-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ignoreMethodAnnotatedBy property to ParameterNumberCheck #11340
Comments
Nice! |
Supression of constructors with this annotation can be achieved via SuppresionXpathSingleFilter:
@tfij we typically try to avoid adding properties to checks when we can handle suppression of special cases with some filter. If you prefer to use a suppression file, you can use the same XPath with https://checkstyle.sourceforge.io/config_filters.html#SuppressionXpathFilter. XPath can also be extended by the
|
@nmancus1 , @rnveach , @strkkk , @pbludov , in the same time, updating Checks to have such properties might also be not that good, as potentially all Checks might need something like this. And it is magic of certain library that not everyone is using. But in the same time instrumenting code with magic annotations is definitely a trend. |
As for me, I prefer to keep checks simple, and only add properties if they cannot be covered by some reasonable/ reliable XPath or other filter. So,
would be my vote. As experience has shown, checks with lots of properties become harder to maintain; not just from a simple code standpoint, but also the logic of how the properties interact with each other. Just as a related note - I think that we need to keep a "repository" of sorts (or entire website page) for all of the XPath related modules that we create, to help users more readily find what they need (with examples). |
usually we resolved such cases, by example in documentation (xdoc) on how to handle frequent edge cases, so googling usually helps to find solution. |
I agree with @romani
How about making it possible to set suppress property for any check configuration? In this case
or something like this. It will solve a problem with two modules maintained separately. It is a generic solution, consistent for all checks and can reuse some existing code. |
we did not make it like this few years ago, as implementation of Xpath was not mature enough, we still have items to finish to make it for all Checks. May be we can start sooner, somebody need to do deep thinking on this. Even we will have this option, it is not user friendly approach and can help users for edge cases and workaround some defects. But we still need to think on most common ways to suppress and allow them to be done by Check properties. This border of xpath to Check special property is not defined by us and not clear for us. |
I am against complicating the check. Such property will fix this particular issue, but it won't work for another. |
I think I might like the idea of adding suppressions to the check itself, locking the 2 together ( #11340 (comment) ). The only downside to that is there would need to be some type of double checking that this new suppression is only suppressing the violations of this check and not accidentally picking up some other check by user configuration error. I am probably more extreme in that we have Otherwise, I don't think I can get behind having the 2 options live together in the same check. |
Deprecation is long for us and painful process for users. Better to keep two options and let them work by same code inside. Xpath is too brutal to user, it tooks awhile for users to understand how to do this, and how to make xpath expression that is required. @tfij, imagine we did not give you xpath expression, how much time you will spend to make it ? But in the same time Lombok like libraries become very popular way of codding now. So suppression by annotation might be well used approach. |
Agree, xpath is very mysterious. Mainly because I don't know what XML structure I'm scanning. |
After reading through the discussion here, and thinking on this some more, I have reconsidered my general position on check properties. If a new check property that is a “feature” is proposed, I stay with my original position. But - if new property is some simple suppression (i.e. checking for a particular annotation) , we should consider it. Most of the time, this will just require some Boolean method used to guard the We do not want to make Checkstyle difficult to configure or inflexible, this will only frustrate users. |
I more care about users experience, implementation pain is limited to few people during PR and eventually forgotten. We use/reconfigure checkstyle more than we spend time to code it. Xpath suppression was good approach to resolve problem on user side quickly, temporary hack. And it might continue to serve this purpose. But custom ignore properties are a way more easy to use. |
Ignore by annotation will be most used ignore/suppression approach. As annotation imply some third-party features/magic that happening in runtime or compilation time, We did not have time to implement ignore properties in Checks, that is why we invested more in xpath to let users has workaround sooner, but if implementation is provided by community, I think it is good to accept it. Especially if we see that such ignore approach can be widely reused. Just example of property to ignore: 0b3a260 that is named "exclude" but meaning is the same as ignore/suppress. |
Let's make a decision here, in regards to this particular issue. If we want to continue discussion about adding check properties in general, let's create a Github discussion and continue there. After thinking on @romani 's comments above, I am for approval of this issue. |
One more example of Lombok usage that cause unwanted violation #11415 |
Hi, is there anything I can do to help make the decision? |
@tfij, can I ask you to help : For now I think we should name it like: ignoreAnnothedBy or something similar. We should avoid usage of "method" or similar words to let it be used for any Check target. Can we also analyze what Checks are highly likely to have such property in future? And what Check unlikely to change behavior by annotated target. |
one more example how annotation make false positive for static analisys - #11481 |
@romani I can handle it next week. One question, by
Do you mean some kind of grid of all checks? or some subset of checks? What format do you expect? |
All Checks, any readable format, to see what we have already |
sounds like ignore parameter that is annotated by, not a method. But check is actually targeting method, so it is not confusion.
to be very explicit where annotation is expected. Ideally user should not read documentation to understand how to configure Check. @rnveach , please approve. |
I'm OK with |
@rnveach , @nrmancuso , please review and approve. @tfij, if no response will be there before 1 january 2023, please mention me here, I will approve issue. |
I would prefer this new property to be called
We could also devise some alternative general naming such as |
Ok, let's move forward with |
Yes, I am on it. |
Label needs to be added (new feature ig) Also, I am not sure how the release works, but I think this was supposed to be released with 10.15.0 #14553 (comment) but the bot has added it to 10.14.3 milestone. |
@sktpy thanks for noticing this, we have added the label. As far as the milestone goes, I think that is automatically recalculated based on what labels were on the issues at the time of release. |
yes, but maintainers has classify issue after fix/merge and update version by github action https://github.com/checkstyle/checkstyle/actions/runs/8369880545/job/22916356794#step:4:130
|
Check name: ParameterNumberCheck
https://checkstyle.org/checks/sizes/parameternumber.html#ParameterNumber
Problem
https://www.baeldung.com/jackson-annotations#1-jsoncreator
https://fasterxml.github.io/jackson-annotations/javadoc/2.7/com/fasterxml/jackson/annotation/JsonCreator.html
If I implement external API, I have no power over the number of parameters, e.g. when creating a DTO class for REST API and deserializing JSON to an object by constructor annotated by @JsonCreator
Solution
I'd like to configure check to ignore this constructor. In general, ignore all methods annotated by
@JsonCreator
, e.g.The PR with the proposal is here #11339
Check already has property
ignoreOverriddenMethods
so new property will make it more general.The text was updated successfully, but these errors were encountered: