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