You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following program, I have explicitly stated that v2 in the block is scoped to the block, and different from the one around.
$ cat foo.rb
v2 = 42
[1, 2, 3].sum do |v; v2|
v2 = 666
v*v
end
puts v2
The inner v2 is absolutely useless, granted, so I should get something like
v2 = 42
[1, 2, 3].sum do |v; _v2|
_v2 = 666
v*v
end
puts v2
Actual behavior
I get
v2 = 42
[1, 2, 3].sum do |v; _v2|
v2 = 666
v*v
end
puts v2
where the inner assignment to v2 was not renamed, so the meaning was changed.
Please use rubocop --debug when pasting rubocop output as it contains additional information.
You asked for it.
$ rubocop --only Lint/UnusedBlockArgument --debug foo.rb
For /private/tmp: configuration from /Users/akim/.rubocop.yml
Default configuration from /opt/local/lib/ruby3.0/gems/3.0.0/gems/rubocop-1.12.1/config/default.yml
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
Please also note that can also opt-in to new cops by default by adding this to your config:
AllCops:
NewCops: enable
Gemspec/DateAssignment: # (new in 1.10)
Enabled: true
Layout/SpaceBeforeBrackets: # (new in 1.7)
Enabled: true
Lint/AmbiguousAssignment: # (new in 1.7)
Enabled: true
Lint/DeprecatedConstants: # (new in 1.8)
Enabled: true
Lint/DuplicateBranch: # (new in 1.3)
Enabled: true
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
Enabled: true
Lint/EmptyBlock: # (new in 1.1)
Enabled: true
Lint/EmptyClass: # (new in 1.3)
Enabled: true
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
Enabled: true
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
Enabled: true
Lint/NumberedParameterAssignment: # (new in 1.9)
Enabled: true
Lint/OrAssignmentToConstant: # (new in 1.9)
Enabled: true
Lint/RedundantDirGlobSort: # (new in 1.8)
Enabled: true
Lint/SymbolConversion: # (new in 1.9)
Enabled: true
Lint/ToEnumArguments: # (new in 1.1)
Enabled: true
Lint/TripleQuotes: # (new in 1.9)
Enabled: true
Lint/UnexpectedBlockArity: # (new in 1.5)
Enabled: true
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
Enabled: true
Style/ArgumentsForwarding: # (new in 1.1)
Enabled: true
Style/CollectionCompact: # (new in 1.2)
Enabled: true
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
Enabled: true
Style/EndlessMethod: # (new in 1.8)
Enabled: true
Style/HashConversion: # (new in 1.10)
Enabled: true
Style/HashExcept: # (new in 1.7)
Enabled: true
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
Enabled: true
Style/NegatedIfElseCondition: # (new in 1.2)
Enabled: true
Style/NilLambda: # (new in 1.3)
Enabled: true
Style/RedundantArgument: # (new in 1.4)
Enabled: true
Style/StringChars: # (new in 1.12)
Enabled: true
Style/SwapValues: # (new in 1.1)
Enabled: true
For more information: https://docs.rubocop.org/rubocop/versioning.html
Inspecting 1 file
Scanning /private/tmp/foo.rb
W
Offenses:
foo.rb:2:22: W: [Correctable] Lint/UnusedBlockArgument: Unused block local variable - v2.
[1, 2, 3].sum do |v; v2|
^^
1 file inspected, 1 offense detected, 1 offense auto-correctable
Finished in 0.1177519999910146 seconds
In the following example rubucop changed the meaning of the program.
Expected behavior
In the following program, I have explicitly stated that v2 in the block is scoped to the block, and different from the one around.
The inner v2 is absolutely useless, granted, so I should get something like
Actual behavior
I get
where the inner assignment to v2 was not renamed, so the meaning was changed.
You asked for it.
Steps to reproduce the problem
See above the self contained example.
RuboCop version
Cheers!
The text was updated successfully, but these errors were encountered: