-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Lint/UnusedMethodArgument overriding reassignment and zsuper #4892
Comments
I think we could augment the "unused argument" logic to tell if there's a call to |
@Drenmi, i thought of that solution. My concern is that argument's value is unused. Is it a big deal? |
@akhramov: Perhaps that is a new cop entirely? Something like:
WDYT? |
@Drenmi, agreed. Should the cop have config options for disabling |
I solved my case by changing the |
Since recently, unused argument cops (`Lint/UnusedBlockArgument` and `Lint/UnusedMethodArgument`) handle the case of shadowed arguments. However, shadowed arguments detection functionality differs semantically from unused arguments cops, and, as such, should be extracted to a separate cop. This change * Introduces `Lint/ShadowedArgument` cop. * Makes `Cop::VariableForce::Assignment` capable of tracking assignment's references. * Removes the shadowed argument detection algorithm from unused argument cops. ## `Lint/ShadowedArgument` cop. ### The algorithm The shadowed argument detection algorithm is slightly improved, so it handles the case when reassignment occurs inside blocks or conditionals of arbitrary nesting. The algoritm takes in account argument reassigning in blocks (fixes rubocop#4898). The algorithm searches for reassignment nodes and reports offenses on them if an argument was reassigned before it was referenced. In case if the argument was reassigned inside a block or conditional, the algorithm signals that precise offense location is undecidable (since it's unknown whether an entity is executed). In this case, offense is reported on argument's declaration node. ### Configuration It's reported (rubocop#4892) that in real-life code there may be situtations when argument shadowing is used in order to pass parameters to `zsuper`: ```ruby def foo(bar) bar = 42 super end ``` If authors tend to use this style, they can use the `IgnoreImplicitReferences` configuration option.
Per #4823 (comment) @mvz discovered an interesting case when overriding reassignment appears with zero-arity super call.
In this case, the value of a variable is unused, so cop suggests to rename the variable. But since
super
call iszsuper
, it captures the reassigned variable:The problem has been resolved by using non-zero arity super:
That being said, reassignment is capured by
zsuper
, but original variable's value is not used.What should we do in such situation? Suggest using
super
instead ofzsuper
? Add a configuration option to ignore this case? Both?Update:
binding
call should have a similar problem.The text was updated successfully, but these errors were encountered: