Skip to content

Commit

Permalink
Support csend on Style/SymbolProc
Browse files Browse the repository at this point in the history
  • Loading branch information
r7kamura authored and bbatsov committed Jul 13, 2022
1 parent 9808e96 commit 0217a37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/change_support_csend_on_stylesymbolproc.md
@@ -0,0 +1 @@
* [#10810](https://github.com/rubocop/rubocop/pull/10810): Support `csend` on `Style/SymbolProc`. ([@r7kamura][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/symbol_proc.rb
Expand Up @@ -89,7 +89,7 @@ class SymbolProc < Base
def_node_matcher :proc_node?, '(send (const {nil? cbase} :Proc) :new)'

# @!method symbol_proc_receiver?(node)
def_node_matcher :symbol_proc_receiver?, '{(send ...) (super ...) zsuper}'
def_node_matcher :symbol_proc_receiver?, '{({csend | send} ...) (super ...) zsuper}'

# @!method symbol_proc?(node)
def_node_matcher :symbol_proc?, <<~PATTERN
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/symbol_proc_spec.rb
Expand Up @@ -12,6 +12,17 @@
RUBY
end

it 'registers an offense for csend' do
expect_offense(<<~RUBY)
coll&.map { |e| e.upcase }
^^^^^^^^^^^^^^^^ Pass `&:upcase` as an argument to `map` instead of a block.
RUBY

expect_correction(<<~RUBY)
coll&.map(&:upcase)
RUBY
end

it 'registers an offense for a block when method in body is unary -/+' do
expect_offense(<<~RUBY)
something.map { |x| -x }
Expand Down

0 comments on commit 0217a37

Please sign in to comment.