fix pkgshare missing slash issue
This commit is contained in:
parent
55246d720e
commit
d8fb850fa9
@ -150,13 +150,13 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Check whether value starts with the formula name and then a "/", " " or EOS
|
# Check whether value starts with the formula name and then a "/", " " or EOS
|
||||||
def starts_with_formula_name?(value)
|
def starts_with_formula_name?(value, prefix = "")
|
||||||
value.match?(%r{#{Regexp.escape(@formula_name)}(/| |$)})
|
value.match?(%r{^#{Regexp.escape(prefix + @formula_name)}(/| |$)})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find "#{share}/foo"
|
# Find "#{share}/foo"
|
||||||
def_node_search :share_formula_name_dstr, <<~EOS
|
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
|
EOS
|
||||||
|
|
||||||
# Find share/"foo"
|
# Find share/"foo"
|
||||||
|
|||||||
@ -449,5 +449,25 @@ describe RuboCop::Cop::FormulaAuditStrict::Text do
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user