fix pkgshare missing slash issue

This commit is contained in:
Rylan Polster 2020-07-12 14:20:50 -04:00
parent 55246d720e
commit d8fb850fa9
2 changed files with 23 additions and 3 deletions

View File

@ -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"

View File

@ -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