From 81a27f861aadd8889793d85676a58058aacd33ad Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 8 Sep 2020 12:01:55 +0900 Subject: [PATCH] [Fix #8664] Fix a false positive for `Naming/BinaryOperatorParameterName` Fixes #8664. This PR fixes a false positive for `Naming/BinaryOperatorParameterName` when naming multibyte character method name. --- CHANGELOG.md | 1 + lib/rubocop/cop/naming/binary_operator_parameter_name.rb | 2 +- .../cop/naming/binary_operator_parameter_name_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7f64c0b986..109fd81496c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * [#8655](https://github.com/rubocop-hq/rubocop/pull/8655): Fix a false positive for `Style/ClassAndModuleChildren` when using cbase class name. ([@koic][]) * [#8654](https://github.com/rubocop-hq/rubocop/pull/8654): Fix a false positive for `Style/SafeNavigation` when checking `foo&.empty?` in a conditional. ([@koic][]) * [#8660](https://github.com/rubocop-hq/rubocop/pull/8660): Fix a false positive for `Style/ClassAndModuleChildren` when using cbase module name. ([@koic][]) +* [#8664](https://github.com/rubocop-hq/rubocop/issues/8664): Fix a false positive for `Naming/BinaryOperatorParameterName` when naming multibyte character method name. ([@koic][]) ### Changes diff --git a/lib/rubocop/cop/naming/binary_operator_parameter_name.rb b/lib/rubocop/cop/naming/binary_operator_parameter_name.rb index 805a4c5b5e7..901ea982579 100644 --- a/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +++ b/lib/rubocop/cop/naming/binary_operator_parameter_name.rb @@ -35,7 +35,7 @@ def on_def(node) def op_method?(name) return false if EXCLUDED.include?(name) - !/\A\w/.match?(name) || OP_LIKE_METHODS.include?(name) + !/\A[[:word:]]/.match?(name) || OP_LIKE_METHODS.include?(name) end end end 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 e3e35d068c9..4902e377e29 100644 --- a/spec/rubocop/cop/naming/binary_operator_parameter_name_spec.rb +++ b/spec/rubocop/cop/naming/binary_operator_parameter_name_spec.rb @@ -81,6 +81,14 @@ def ===(string) RUBY end + it 'does not register an offense for multibyte character method name' do + expect_no_offenses(<<~RUBY) + def do_something(string) + string + end + RUBY + end + it 'does not register an offense for non binary operators' do expect_no_offenses(<<~RUBY) def -@; end