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

Strict unused variable enforces lambda parameters #1355

Merged
merged 5 commits into from
May 27, 2020

Conversation

ferozco
Copy link
Contributor

@ferozco ferozco commented May 27, 2020

Before this PR

StrictUnusedVariable would not ensure that all lambda parameters were unused

After this PR

==COMMIT_MSG==
StrictUnusedVariable checks for unused lambda parameters
==COMMIT_MSG==

Possible downsides?

Some code bases may have had existing conventions for denoting unused lambda parameters. However the fix that comes along with the rule should prevent upgrades from being blocked

@changelog-app
Copy link

changelog-app bot commented May 27, 2020

Generate changelog in changelog/@unreleased

Type

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

Description

StrictUnusedVariable checks for unused lambda parameters

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from CRogers May 27, 2020 19:09
boolean isPrivateMethod = methodSymbol.getModifiers().contains(Modifier.PRIVATE);
int index = methodSymbol.params.indexOf(varSymbol);
Preconditions.checkState(index != -1, "symbol must be a parameter to the owning method");
Copy link
Contributor

Choose a reason for hiding this comment

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

might be nice to log the symbol and the method if we're gonna throw? :)

"import java.util.function.BiFunction;",
"class Test {",
" private static BiFunction<String, String, Integer> doStuff() {",
" BiFunction<String, String, Integer> first = (String value1, String value2) -> 1;",
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 maybe use one of them to check that it only renames the other one

@dansanduleac
Copy link
Contributor

👍

@pkoenig10
Copy link
Member

👍

@bulldozer-bot bulldozer-bot bot merged commit 620c65b into develop May 27, 2020
@bulldozer-bot bulldozer-bot bot deleted the fo/unused-lambda-params branch May 27, 2020 19:30
@svc-autorelease
Copy link
Collaborator

Released 3.15.0

@dansanduleac
Copy link
Contributor

dansanduleac commented May 28, 2020

This just broke some code by dropping the contents before a lambda with a single (used) parameter i -> i + 1 upon auto-fixing.

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