Skip to content
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

Merged
merged 7 commits into from
Jul 7, 2020
Merged

Conversation

ferozco
Copy link
Contributor

@ferozco ferozco commented Jul 7, 2020

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

@changelog-app
Copy link

changelog-app bot commented Jul 7, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Add TooManyArguments errorprone rule which prevents interfaces from having more than 10 arguments

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from iamdanfox July 7, 2020 16:08
if (tree.getParameters().size() > MAX_NUM_ARGS) {
return buildDescription(tree)
.setMessage("Interfaces can take at most " + MAX_NUM_ARGS + " arguments.")
.build();
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about 5?

Copy link
Contributor Author

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

Copy link
Contributor

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

@ferozco
Copy link
Contributor Author

ferozco commented Jul 7, 2020

@carterkozak I think this is ready to go


@AutoService(BugChecker.class)
@BugPattern(
name = "TooManyArguments",
Copy link
Contributor

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?

Copy link
Contributor

@carterkozak carterkozak left a 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

@bulldozer-bot bulldozer-bot bot merged commit 87b077a into develop Jul 7, 2020
@bulldozer-bot bulldozer-bot bot deleted the fo/too-many-args branch July 7, 2020 19:59
@svc-autorelease
Copy link
Collaborator

Released 3.34.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants