From cefc56a40ba86efc95cb966b9cfb3ec9abf49a6c Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 3 Sep 2021 09:27:12 +0900 Subject: [PATCH] Suppress `Lint/AmbiguousOperatorPrecedence` offense This PR suppresses the following `Lint/AmbiguousOperatorPrecedence` offense. ```console % bundle exec rake (snip) Offenses: lib/rubocop/ast/node.rb:428:44: W: [Correctable] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. return true if special_keyword? || send_type? && prefix_not? ^^^^^^^^^^^^^^^^^^^^^^^^^ spec/rubocop/ast/node_pattern/lexer_spec.rb:70:27: W: [Correctable] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. expect(types).to eq [:tNODE_TYPE] * 2 + [:tPARAM_CONST] * 7 ^^^^^^^^^^^^^^^^^ spec/rubocop/ast/node_pattern/lexer_spec.rb:70:47: W: [Correctable] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. expect(types).to eq [:tNODE_TYPE] * 2 + [:tPARAM_CONST] * 7 ^^^^^^^^^^^^^^^^^^^ 162 files inspected, 3 offenses detected, 3 offenses auto-correctable ``` https://github.com/rubocop/rubocop-ast/pull/206/checks?check_run_id=3501466011 --- lib/rubocop/ast/node.rb | 2 +- spec/rubocop/ast/node_pattern/lexer_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rubocop/ast/node.rb b/lib/rubocop/ast/node.rb index f1ada86dc..f37e5e74f 100644 --- a/lib/rubocop/ast/node.rb +++ b/lib/rubocop/ast/node.rb @@ -425,7 +425,7 @@ def loop_keyword? end def keyword? - return true if special_keyword? || send_type? && prefix_not? + return true if special_keyword? || (send_type? && prefix_not?) return false unless KEYWORDS.include?(type) !OPERATOR_KEYWORDS.include?(type) || loc.operator.is?(type.to_s) diff --git a/spec/rubocop/ast/node_pattern/lexer_spec.rb b/spec/rubocop/ast/node_pattern/lexer_spec.rb index 0d81f0270..fb232c5ce 100644 --- a/spec/rubocop/ast/node_pattern/lexer_spec.rb +++ b/spec/rubocop/ast/node_pattern/lexer_spec.rb @@ -67,7 +67,7 @@ it 'distinguishes them' do types = tokens.map(&:first) - expect(types).to eq [:tNODE_TYPE] * 2 + [:tPARAM_CONST] * 7 + expect(types).to eq ([:tNODE_TYPE] * 2) + ([:tPARAM_CONST] * 7) zz, percent_zz = tokens.last(2).map(&:last).map(&:first) expect(zz).to eq 'Zz' expect(percent_zz).to eq 'Zz'