From 2a49404fbdd731d7266c5f01d2bd88ba4b229023 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 29 Aug 2021 19:56:55 +0900 Subject: [PATCH] Fix a build error This PR fixes the following build error. ```console bundle exec rubocop (snip) Offenses: lib/rubocop/cop/mixin/preceding_following_alignment.rb:96:9: W: [Correctable] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. range.source[-1] == '=' && line[range.last_column - 1] == '=' || ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/rubocop/cop/mixin/preceding_following_alignment.rb:101:9: W: [Correctable] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. range.source == '<<' && line[range.last_column - 1] == '=' || ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/rubocop/cop/mixin/preceding_following_alignment.rb:102:11: W: [Correctable] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. range.source[-1] == '=' && line[(range.last_column - 2)..(range.last_column - 1)] == '<<' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/rubocop/cop/mixin/preceding_following_alignment.rb:102:101: C: Layout/LineLength: Line is too long. [101/100] (range.source[-1] == '=' && line[(range.last_column - 2)..(range.last_column - 1)] == '<<') ^ 1304 files inspected, 4 offenses detected, 3 offenses corrected ``` https://github.com/rubocop/rubocop/runs/3453863216 --- lib/rubocop/cop/mixin/preceding_following_alignment.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/rubocop/cop/mixin/preceding_following_alignment.rb b/lib/rubocop/cop/mixin/preceding_following_alignment.rb index 1c66a94b580..da47e08fecd 100644 --- a/lib/rubocop/cop/mixin/preceding_following_alignment.rb +++ b/lib/rubocop/cop/mixin/preceding_following_alignment.rb @@ -93,13 +93,15 @@ def aligned_char?(range, line) end def aligned_assignment?(range, line) - range.source[-1] == '=' && line[range.last_column - 1] == '=' || + (range.source[-1] == '=' && line[range.last_column - 1] == '=') || aligned_with_append_operator?(range, line) end def aligned_with_append_operator?(range, line) - range.source == '<<' && line[range.last_column - 1] == '=' || - range.source[-1] == '=' && line[(range.last_column - 2)..(range.last_column - 1)] == '<<' + last_column = range.last_column + + (range.source == '<<' && line[last_column - 1] == '=') || + (range.source[-1] == '=' && line[(last_column - 2)..(last_column - 1)] == '<<') end def aligned_identical?(range, line)