diff --git a/Library/Homebrew/rubocops/text.rb b/Library/Homebrew/rubocops/text.rb index d925106240..1e0c2ab7d6 100644 --- a/Library/Homebrew/rubocops/text.rb +++ b/Library/Homebrew/rubocops/text.rb @@ -150,13 +150,13 @@ module RuboCop end # Check whether value starts with the formula name and then a "/", " " or EOS - def starts_with_formula_name?(value) - value.match?(%r{#{Regexp.escape(@formula_name)}(/| |$)}) + def starts_with_formula_name?(value, prefix = "") + value.match?(%r{^#{Regexp.escape(prefix + @formula_name)}(/| |$)}) end # Find "#{share}/foo" def_node_search :share_formula_name_dstr, <<~EOS - $(dstr (begin (send nil? :share)) (str #starts_with_formula_name?)) + $(dstr (begin (send nil? :share)) (str #starts_with_formula_name?("/"))) EOS # Find share/"foo" diff --git a/Library/Homebrew/test/rubocops/text_spec.rb b/Library/Homebrew/test/rubocops/text_spec.rb index 4ccb551145..3960272dbc 100644 --- a/Library/Homebrew/test/rubocops/text_spec.rb +++ b/Library/Homebrew/test/rubocops/text_spec.rb @@ -449,5 +449,25 @@ describe RuboCop::Cop::FormulaAuditStrict::Text do end RUBY end + + it "when formula name appears afer `share/\"bar\"`" do + expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") + class Foo < Formula + def install + ohai share/"bar/foo" + end + end + RUBY + end + + it "when formula name appears afer `\"\#{share}/bar\"`" do + expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") + class Foo < Formula + def install + ohai "\#{share}/bar/foo" + end + end + RUBY + end end end