From 2d8f39b1a49c1180dd392f68266bd5daf03d7a8c Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 22 May 2026 09:07:00 +0100 Subject: [PATCH] Fix dynamic completion audit crash - Avoid crashing on formulae that build `shells:` from a loop. - Keep the cop limited to literal shell lists it can safely rewrite. - Cover the `rustup` completion pattern that exposed the issue. --- Library/Homebrew/rubocops/lines.rb | 5 ++++- .../lines/generate_completions_spec.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index d3683d0b243d3..eacd0fee9d3f0 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -662,7 +662,10 @@ def audit_formula(formula_nodes) methods.each do |method| next unless method.source.include?("shells:") - shells << method.source.match(/shells: \[(:bash|:zsh|:fish)\]/).captures.first + shell = method.source[/shells: \[(:bash|:zsh|:fish)\]/, 1] + next if shell.nil? + + shells << shell offenses << method end diff --git a/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb b/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb index 245a013d50e10..be40a5a7cc719 100644 --- a/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb +++ b/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb @@ -143,5 +143,23 @@ def install end RUBY end + + it "does not report an offense when shells are generated dynamically" do + expect_no_offenses(<<~RUBY) + class Foo < Formula + name "foo" + + def install + generate_completions_from_executable(bin/"foo", "completions") + [:zsh, :bash].each do |shell| + generate_completions_from_executable( + bin/"foo", "completions", shell.to_s, "bar", shells: [shell], base_name: "bar", + shell_parameter_format: :none + ) + end + end + end + RUBY + end end end