-
Notifications
You must be signed in to change notification settings - Fork 135
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 TooManyArguments errorprone rule #1447
Conversation
Generate changelog in
|
baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/TooManyArguments.java
Outdated
Show resolved
Hide resolved
if (tree.getParameters().size() > MAX_NUM_ARGS) { | ||
return buildDescription(tree) | ||
.setMessage("Interfaces can take at most " + MAX_NUM_ARGS + " arguments.") | ||
.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No suggested fix to lop off a few unimportant params? ;-)
We might want to add something to the message suggesting an args object with a builder, potentially recommending immutables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to have an autofix since it would leave behind code that didn't compile.
Happy to improve the message with ideas on how to solve the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to have an autofix since it would leave behind code that didn't compile.
Sorry, I should have included a /s
tag! Agree we shouldn't break code.
…prone/TooManyArguments.java Co-authored-by: Carter Kozak <[email protected]>
severity = SeverityLevel.WARNING, | ||
summary = "Prefer Interface that take few arguments rather than many.") | ||
public final class TooManyArguments extends BugChecker implements BugChecker.MethodTreeMatcher { | ||
private static final int MAX_NUM_ARGS = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about 5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can ratchet it down over time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to start high and ratchet down
@carterkozak I think this is ready to go |
|
||
@AutoService(BugChecker.class) | ||
@BugPattern( | ||
name = "TooManyArguments", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding this to the readme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm aside from the nit
…e into fo/too-many-args
Released 3.34.0 |
Before this PR
Users could define unwieldy interfaces that took a large number of parameters.
After this PR
==COMMIT_MSG==
Add
TooManyArguments
errorprone rule which prevents interfaces from having more than 10 arguments==COMMIT_MSG==
Possible downsides?
There are definitely cases of people with larger interfaces so upgrades will be blocked and manual action will be required