From d8fb850fa9fd535a0e08149b4faed2a1ce73a44a Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Sun, 12 Jul 2020 14:20:50 -0400 Subject: [PATCH] fix pkgshare missing slash issue --- Library/Homebrew/rubocops/text.rb | 6 +++--- Library/Homebrew/test/rubocops/text_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) 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