rubocops/text: Enforce bin/"formula"
instead of "#{bin}/formula"
This commit is contained in:
parent
321498c327
commit
96400e01e1
@ -137,6 +137,11 @@ module RuboCop
|
||||
problem "Use `\#{pkgshare}` instead of `\#{share}/#{@formula_name}`"
|
||||
end
|
||||
|
||||
interpolated_bin_path_starts_with(body_node, "/#{@formula_name}") do |bin_node|
|
||||
offending_node(bin_node)
|
||||
problem "Use `bin/\"#{@formula_name}\"` instead of `\"\#{bin}/#{@formula_name}\"`"
|
||||
end
|
||||
|
||||
return if formula_tap != "homebrew-core"
|
||||
|
||||
find_method_with_args(body_node, :env, :std) do
|
||||
@ -154,6 +159,11 @@ module RuboCop
|
||||
$(dstr (begin (send nil? :share)) (str #path_starts_with?(%1)))
|
||||
EOS
|
||||
|
||||
# Find "#{bin}/foo"
|
||||
def_node_search :interpolated_bin_path_starts_with, <<~EOS
|
||||
$(dstr (begin (send nil? :bin)) (str #path_starts_with?(%1)))
|
||||
EOS
|
||||
|
||||
# Find share/"foo"
|
||||
def_node_search :share_path_starts_with, <<~EOS
|
||||
$(send (send nil? :share) :/ (str #path_starts_with?(%1)))
|
||||
|
@ -6,6 +6,16 @@
|
||||
|
||||
|
||||
class RuboCop::Cop::FormulaAuditStrict::Text
|
||||
sig do
|
||||
params(
|
||||
node: RuboCop::AST::Node,
|
||||
pattern: T.any(String, Symbol),
|
||||
kwargs: T.untyped,
|
||||
block: T.untyped
|
||||
).returns(T.untyped)
|
||||
end
|
||||
def interpolated_bin_path_starts_with(node, *pattern, **kwargs, &block); end
|
||||
|
||||
sig do
|
||||
params(
|
||||
node: RuboCop::AST::Node,
|
||||
|
@ -131,5 +131,16 @@ RSpec.describe RuboCop::Cop::FormulaAuditStrict::Text do
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'reports an offense if "\#{bin}/<formula name>" is present' do
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
test do
|
||||
ohai "\#{bin}/foo", "-v"
|
||||
^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `bin/"foo"` instead of `"\#{bin}/foo"`
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user