From 3c5d3aefaf6dde1337d5662a06caad0dc5c1a525 Mon Sep 17 00:00:00 2001 From: Zachary Jones Date: Fri, 16 Oct 2020 18:09:38 -0400 Subject: [PATCH] [Fix #8901] Fix a false positive for `Naming/BinaryOperatorParameterName` 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). --- CHANGELOG.md | 2 ++ lib/rubocop/cop/naming/binary_operator_parameter_name.rb | 2 +- .../cop/naming/binary_operator_parameter_name_spec.rb | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d7b20e30b..df36b728eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -4998,3 +4999,4 @@ [@ghiculescu]: https://github.com/ghiculescu [@hatkyinc2]: https://github.com/hatkyinc2 [@AllanSiqueira]: https://github.com/allansiqueira +[@zajn]: https://github.com/zajn diff --git a/lib/rubocop/cop/naming/binary_operator_parameter_name.rb b/lib/rubocop/cop/naming/binary_operator_parameter_name.rb index 901ea982579..21b8f591dbf 100644 --- a/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +++ b/lib/rubocop/cop/naming/binary_operator_parameter_name.rb @@ -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])) _) diff --git a/spec/rubocop/cop/naming/binary_operator_parameter_name_spec.rb b/spec/rubocop/cop/naming/binary_operator_parameter_name_spec.rb index 4902e377e29..266349bf921 100644 --- a/spec/rubocop/cop/naming/binary_operator_parameter_name_spec.rb +++ b/spec/rubocop/cop/naming/binary_operator_parameter_name_spec.rb @@ -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