Skip to content

Commit

Permalink
Merge pull request #12207 from koic/fix_an_error_for_style_operator_m…
Browse files Browse the repository at this point in the history
…ethod_call

[Fix #12205] Fix an error for `Style/OperatorMethodCall`
  • Loading branch information
koic committed Sep 19, 2023
2 parents 1af7e11 + ed9a4bd commit d6b5ecf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_style_operator_method_call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12205](https://github.com/rubocop/rubocop/issues/12205): Fix an error for `Style/OperatorMethodCall` when using `foo bar./ baz`. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/operator_method_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def anonymous_forwarding?(argument)

def wrap_in_parentheses_if_chained(corrector, node)
return unless node.parent&.call_type?
return if node.parent.first_argument == node

operator = node.loc.selector

Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/operator_method_call_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
RUBY
end

it "registers an offense when using `foo bar.#{operator_method} baz`" do
expect_offense(<<~RUBY)
foo bar.#{operator_method} baz
^ Redundant dot detected.
RUBY

expect_correction(<<~RUBY)
foo bar #{operator_method} baz
RUBY
end

it "registers an offense when using `foo.#{operator_method}(bar)`" do
expect_offense(<<~RUBY, operator_method: operator_method)
foo.#{operator_method}(bar)
Expand Down

0 comments on commit d6b5ecf

Please sign in to comment.