From c09bf73e455b5062d141dd3e7d017c4eea4453f4 Mon Sep 17 00:00:00 2001 From: Ryo Nakamura Date: Wed, 13 Jul 2022 12:27:07 +0900 Subject: [PATCH] Support `csend` on `Style/SymbolProc` --- changelog/change_support_csend_on_stylesymbolproc.md | 1 + lib/rubocop/cop/style/symbol_proc.rb | 2 +- spec/rubocop/cop/style/symbol_proc_spec.rb | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelog/change_support_csend_on_stylesymbolproc.md diff --git a/changelog/change_support_csend_on_stylesymbolproc.md b/changelog/change_support_csend_on_stylesymbolproc.md new file mode 100644 index 00000000000..8e44d84b294 --- /dev/null +++ b/changelog/change_support_csend_on_stylesymbolproc.md @@ -0,0 +1 @@ +* [#10810](https://github.com/rubocop/rubocop/pull/10810): Support `csend` on `Style/SymbolProc`. ([@r7kamura][]) diff --git a/lib/rubocop/cop/style/symbol_proc.rb b/lib/rubocop/cop/style/symbol_proc.rb index dede2985255..d0efabf62aa 100644 --- a/lib/rubocop/cop/style/symbol_proc.rb +++ b/lib/rubocop/cop/style/symbol_proc.rb @@ -81,7 +81,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 diff --git a/spec/rubocop/cop/style/symbol_proc_spec.rb b/spec/rubocop/cop/style/symbol_proc_spec.rb index 22bef0022f3..1beefc91aa4 100644 --- a/spec/rubocop/cop/style/symbol_proc_spec.rb +++ b/spec/rubocop/cop/style/symbol_proc_spec.rb @@ -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 }