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
False positive on Hash#reject with first numbered parameter #10864
Labels
Comments
8 tasks
koic
added a commit
to koic/rubocop
that referenced
this issue
Aug 4, 2022
Fixes rubocop#10864. This PR fixes a false positive for `Style/SymbolProc` when using `Hash#reject`. The same is true for `Haash#select`. ```ruby {foo: :bar}.reject { p _1 } # `_1` is `:foo` {foo: :bar}.select { p _1 } # `_1` is `:foo` {foo: :bar}.detect { p _1 } # `_1` is `[:foo, :bar]` {foo: :bar}.map { p _1 } # `_1` is `[:foo, :bar]` ``` It fixes `on_block` method because the same issue occurs in normal blocks. ```ruby {foo: :bar}.select {|item| item.nil? } #=> no erros. {foo: :bar}.select(&:nil?) #=> wrong number of arguments (given 1, expected 0) (ArgumentError) ``` `Style/SymbolProc` is already marked as unsafe, but it avoids avoidable issues.
bbatsov
pushed a commit
that referenced
this issue
Aug 4, 2022
Fixes #10864. This PR fixes a false positive for `Style/SymbolProc` when using `Hash#reject`. The same is true for `Haash#select`. ```ruby {foo: :bar}.reject { p _1 } # `_1` is `:foo` {foo: :bar}.select { p _1 } # `_1` is `:foo` {foo: :bar}.detect { p _1 } # `_1` is `[:foo, :bar]` {foo: :bar}.map { p _1 } # `_1` is `[:foo, :bar]` ``` It fixes `on_block` method because the same issue occurs in normal blocks. ```ruby {foo: :bar}.select {|item| item.nil? } #=> no erros. {foo: :bar}.select(&:nil?) #=> wrong number of arguments (given 1, expected 0) (ArgumentError) ``` `Style/SymbolProc` is already marked as unsafe, but it avoids avoidable issues.
WJWH
pushed a commit
to WJWH/rubocop
that referenced
this issue
Aug 8, 2022
Fixes rubocop#10864. This PR fixes a false positive for `Style/SymbolProc` when using `Hash#reject`. The same is true for `Haash#select`. ```ruby {foo: :bar}.reject { p _1 } # `_1` is `:foo` {foo: :bar}.select { p _1 } # `_1` is `:foo` {foo: :bar}.detect { p _1 } # `_1` is `[:foo, :bar]` {foo: :bar}.map { p _1 } # `_1` is `[:foo, :bar]` ``` It fixes `on_block` method because the same issue occurs in normal blocks. ```ruby {foo: :bar}.select {|item| item.nil? } #=> no erros. {foo: :bar}.select(&:nil?) #=> wrong number of arguments (given 1, expected 0) (ArgumentError) ``` `Style/SymbolProc` is already marked as unsafe, but it avoids avoidable issues.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using
Hash#reject
against the first numbered parameter, Rubocop incorrectly suggests to use the&:{method}
syntax.Ex. It suggests
some_hash.reject(&:nil?)
when the code in question issome_hash.reject { _1.nil? }
This is also an auto-correctable offense, which means it could break working code.
I haven't tested, but my assuption is that there is similar incorrect behaviour for a whole class of enumberable methods such as
select
,any
, etc.Expected behavior
Actual behavior
Steps to reproduce the problem
Create
tmp.rb
as follows:Run
rubocop tmp.rb
RuboCop version
The text was updated successfully, but these errors were encountered: