Skip to content
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

Support csend on Style/SymbolProc #10810

Merged
merged 1 commit into from Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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][])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [#10810](https://github.com/rubocop/rubocop/pull/10810): Support `csend` on `Style/SymbolProc`. ([@r7kamura][])
* [#10810](https://github.com/rubocop/rubocop/pull/10810): Support safe navigation operator on `Style/SymbolProc`. ([@r7kamura][])

2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/symbol_proc.rb
Expand Up @@ -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}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def_node_matcher :symbol_proc_receiver?, '{({csend | send} ...) (super ...) zsuper}'
def_node_matcher :symbol_proc_receiver?, '{(call ...) (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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it 'registers an offense for csend' do
it 'registers an offense for safe navigation operator' 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