refactor share path node matcher
This commit is contained in:
parent
d8fb850fa9
commit
936f4bbff4
@ -132,12 +132,12 @@ module RuboCop
|
|||||||
problem "`env :userpaths` in homebrew/core formulae is deprecated"
|
problem "`env :userpaths` in homebrew/core formulae is deprecated"
|
||||||
end
|
end
|
||||||
|
|
||||||
share_formula_name(body_node) do |share_node|
|
share_path_starts_with(body_node, @formula_name) do |share_node|
|
||||||
offending_node(share_node)
|
offending_node(share_node)
|
||||||
problem "Use `pkgshare` instead of `share/\"#{@formula_name}\"`"
|
problem "Use `pkgshare` instead of `share/\"#{@formula_name}\"`"
|
||||||
end
|
end
|
||||||
|
|
||||||
share_formula_name_dstr(body_node) do |share_node|
|
interpolated_share_path_starts_with(body_node, "/#{@formula_name}") do |share_node|
|
||||||
offending_node(share_node)
|
offending_node(share_node)
|
||||||
problem "Use `\#{pkgshare}` instead of `\#{share}/#{@formula_name}`"
|
problem "Use `\#{pkgshare}` instead of `\#{share}/#{@formula_name}`"
|
||||||
end
|
end
|
||||||
@ -150,18 +150,18 @@ 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, prefix = "")
|
def path_starts_with?(path, starts_with)
|
||||||
value.match?(%r{^#{Regexp.escape(prefix + @formula_name)}(/| |$)})
|
path.match?(%r{^#{Regexp.escape(starts_with)}(/| |$)})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find "#{share}/foo"
|
# Find "#{share}/foo"
|
||||||
def_node_search :share_formula_name_dstr, <<~EOS
|
def_node_search :interpolated_share_path_starts_with, <<~EOS
|
||||||
$(dstr (begin (send nil? :share)) (str #starts_with_formula_name?("/")))
|
$(dstr (begin (send nil? :share)) (str #path_starts_with?(%1)))
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
# Find share/"foo"
|
# Find share/"foo"
|
||||||
def_node_search :share_formula_name, <<~EOS
|
def_node_search :share_path_starts_with, <<~EOS
|
||||||
$(send (send nil? :share) :/ (str #starts_with_formula_name?))
|
$(send (send nil? :share) :/ (str #path_starts_with?(%1)))
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user