Skip to content

Commit

Permalink
[Fix #8901] Fix a false positive for `Naming/BinaryOperatorParameterN…
Browse files Browse the repository at this point in the history
…ame`

Defining the match operator `=~` triggered a false positive for
`Naming/BinaryOperatorParameterName`, which should not be triggered
for pattern/matchable relations according to the [Ruby style guide](https://rubystyle.guide/#other-arg).
  • Loading branch information
Zajn authored and marcandre committed Oct 17, 2020
1 parent be8b179 commit 3c5d3ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@
* [#8490](https://github.com/rubocop-hq/rubocop/pull/8490): **(Breaking)** Change logic for cop department name computation. Cops inside deep namespaces (5 or more levels deep) now belong to departments with names that are calculated by joining module names starting from the third one with slashes as separators. For example, cop `Rubocop::Cop::Foo::Bar::Baz` now belongs to `Foo/Bar` department (previously it was `Bar`). ([@dsavochkin][])
* [#8692](https://github.com/rubocop-hq/rubocop/pull/8692): Default changed to disallow `Layout/TrailingWhitespace` in heredoc. ([@marcandre][])
* [#8894](https://github.com/rubocop-hq/rubocop/issues/8894): Make `Security/Open` aware of `URI.open`. ([@koic][])
* [#8901](https://github.com/rubocop-hq/rubocop/issues/8901): Fix false positive for `Naming/BinaryOperatorParameterName` when defining `=~`. ([@zajn][])

## 0.93.1 (2020-10-12)

Expand Down Expand Up @@ -4998,3 +4999,4 @@
[@ghiculescu]: https://github.com/ghiculescu
[@hatkyinc2]: https://github.com/hatkyinc2
[@AllanSiqueira]: https://github.com/allansiqueira
[@zajn]: https://github.com/zajn
2 changes: 1 addition & 1 deletion lib/rubocop/cop/naming/binary_operator_parameter_name.rb
Expand Up @@ -18,7 +18,7 @@ class BinaryOperatorParameterName < Base
'name its argument `other`.'

OP_LIKE_METHODS = %i[eql? equal?].freeze
EXCLUDED = %i[+@ -@ [] []= << === `].freeze
EXCLUDED = %i[+@ -@ [] []= << === ` =~].freeze

def_node_matcher :op_method_candidate?, <<~PATTERN
(def [#op_method? $_] (args $(arg [!:other !:_other])) _)
Expand Down
Expand Up @@ -99,4 +99,10 @@ def *(a, b); end # Quite strange, but legal ruby.
def `(cmd); end
RUBY
end

it 'does not register an offense for the match operator' do
expect_no_offenses(<<~RUBY)
def =~(regexp); end
RUBY
end
end

0 comments on commit 3c5d3ae

Please sign in to comment.