From 1e4c8788c4060fd11134f656637f83290d1c5724 Mon Sep 17 00:00:00 2001 From: Bill Ruddock Date: Sun, 12 Jul 2020 03:24:38 +0100 Subject: [PATCH] Recognise < > as comparison operators in cond assign --- CHANGELOG.md | 4 ++++ lib/rubocop/cop/style/conditional_assignment.rb | 2 +- .../style/conditional_assignment_assign_to_condition_spec.rb | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88ef3c4e6e4..c289f902a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ * [#8480](https://github.com/rubocop-hq/rubocop/issues/8480): Tweak callback list of `Lint/MissingSuper`. ([@marcandre][]) * [#8481](https://github.com/rubocop-hq/rubocop/pull/8481): Fix autocorrect for elements with newlines in `Style/SymbolArray` and `Style/WordArray`. ([@biinari][]) +### Changes + +* [#8487](https://github.com/rubocop-hq/rubocop/pull/8487): Detect `<` and `>` as comparison operators in `Style/ConditionalAssignment` cop. ([@biinari][]) + ## 0.89.0 (2020-08-05) ### New features diff --git a/lib/rubocop/cop/style/conditional_assignment.rb b/lib/rubocop/cop/style/conditional_assignment.rb index c68be1a4abe..9e70f99a535 100644 --- a/lib/rubocop/cop/style/conditional_assignment.rb +++ b/lib/rubocop/cop/style/conditional_assignment.rb @@ -233,7 +233,7 @@ class ConditionalAssignment < Cop def_node_matcher :assignment_type?, <<~PATTERN { #{ASSIGNMENT_TYPES.join(' ')} - (send _recv {:[]= :<< :=~ :!~ :<=> #end_with_eq?} ...) + (send _recv {:[]= :<< :=~ :!~ :<=> #end_with_eq? :< :>} ...) } PATTERN diff --git a/spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb b/spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb index 1870f35b115..d2743dc49a3 100644 --- a/spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb +++ b/spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb @@ -282,6 +282,8 @@ it_behaves_like('comparison methods', '===') it_behaves_like('comparison methods', '<=') it_behaves_like('comparison methods', '>=') + it_behaves_like('comparison methods', '<') + it_behaves_like('comparison methods', '>') context 'empty branch' do it 'allows an empty if statement' do