Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
76 additions
and
9 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog/fix_a_false_positive_for_style_symbol_proc_when_using_hash_reject.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#10864](https://github.com/rubocop/rubocop/issues/10864): Fix a false positive for `Style/SymbolProc` when using `Hash#reject`. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters