Make the bin starts_with
method its own thing as it needs more args
- I couldn't get https://docs.rubocop.org/rubocop-ast/node_pattern.html#param_name-for-named-parameters to work like it said it should (bad syntax in the node_matcher, apart from with `bin = false` which RuboCop complained about boolean args not being named), so here's a workaround.
This commit is contained in:
parent
3713939e0d
commit
ace23ce735
@ -137,7 +137,7 @@ module RuboCop
|
||||
problem "Use `\#{pkgshare}` instead of `\#{share}/#{@formula_name}`"
|
||||
end
|
||||
|
||||
interpolated_bin_path_starts_with(body_node, "/#{@formula_name}", true) do |bin_node|
|
||||
interpolated_bin_path_starts_with(body_node, "/#{@formula_name}") do |bin_node|
|
||||
offending_node(bin_node)
|
||||
cmd = bin_node.source.match(%r{\#{bin}/(\S+)})[1]&.delete_suffix('"') || @formula_name
|
||||
problem "Use `bin/\"#{cmd}\"` instead of `\"\#{bin}/#{cmd}\"`"
|
||||
@ -152,11 +152,15 @@ module RuboCop
|
||||
|
||||
# Check whether value starts with the formula name and then a "/", " " or EOS.
|
||||
# If we're checking for "#{bin}", we also check for "-" since similar binaries also don't need interpolation.
|
||||
def path_starts_with?(path, starts_with, bin = false)
|
||||
def path_starts_with?(path, starts_with, bin: false)
|
||||
ending = bin ? "/| |-|$" : "/| |$"
|
||||
path.match?(/^#{Regexp.escape(starts_with)}(#{ending})/)
|
||||
end
|
||||
|
||||
def path_starts_with_bin?(path, starts_with)
|
||||
path_starts_with?(path, starts_with, bin: true)
|
||||
end
|
||||
|
||||
# Find "#{share}/foo"
|
||||
def_node_search :interpolated_share_path_starts_with, <<~EOS
|
||||
$(dstr (begin (send nil? :share)) (str #path_starts_with?(%1)))
|
||||
@ -164,7 +168,7 @@ module RuboCop
|
||||
|
||||
# Find "#{bin}/foo" and "#{bin}/foo-bar"
|
||||
def_node_search :interpolated_bin_path_starts_with, <<~EOS
|
||||
$(dstr (begin (send nil? :bin)) (str #path_starts_with?(%1, %2)))
|
||||
$(dstr (begin (send nil? :bin)) (str #path_starts_with_bin?(%1)))
|
||||
EOS
|
||||
|
||||
# Find share/"foo"
|
||||
|
Loading…
x
Reference in New Issue
Block a user