From 02c9cc0720e1cf9a7e0d22c4132ec7ca0839de77 Mon Sep 17 00:00:00 2001 From: Max Eisner <4730112+max-ae@users.noreply.github.com> Date: Thu, 11 Aug 2022 16:56:04 +0200 Subject: [PATCH] add check if executable and subcmd are the same before combining MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit e.g. ˚jrsonnet˚ needs this --- Library/Homebrew/rubocops/lines.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index b465ab6599..b12be1b1b8 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -517,7 +517,14 @@ module RuboCop return if offenses.blank? - T.must(offenses[0...-1]).each do |node| + T.must(offenses[0...-1]).each_with_index do |node, i| + # executable and subcmd have to be the same to be combined + if node.arguments.first != offenses[i + 1].arguments.first || + node.arguments.second != offenses[i + 1].arguments.second + shells.delete_at(i) + next + end + offending_node(node) problem "Use a single `generate_completions_from_executable` " \ "call combining all specified shells." do |corrector| @@ -526,6 +533,8 @@ module RuboCop end end + return if shells.length <= 1 # no shells to combine left + offending_node(offenses.last) replacement = if (%w[:bash :zsh :fish] - shells).empty? @offensive_node.source.sub(/shells: \[(:bash|:zsh|:fish)\]/, "")