rubocops/text: Allow bin
interpolation inside word arrays
- We discovered that the following syntax in the formula `sqlsmith` should actually be OK because the `\n` is like whitespace. ```ruby cmd = %W[ #{bin}/sqlsmith --threads=4 --timeout=10 ] shell_output(cmd) ```
This commit is contained in:
parent
9279693a34
commit
cb8769c2a0
@ -140,6 +140,8 @@ module RuboCop
|
||||
end
|
||||
|
||||
interpolated_bin_path_starts_with(body_node, "/#{@formula_name}") do |bin_node|
|
||||
next if bin_node.ancestors.any?(&:array_type?)
|
||||
|
||||
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}\"`" do |corrector|
|
||||
|
@ -132,6 +132,7 @@ RSpec.describe RuboCop::Cop::FormulaAuditStrict::Text do
|
||||
RUBY
|
||||
end
|
||||
|
||||
context "for interpolated bin paths" do
|
||||
it 'reports an offense & autocorrects if "\#{bin}/<formula_name>" or other dashed binaries too are present' do
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
@ -166,4 +167,19 @@ RSpec.describe RuboCop::Cop::FormulaAuditStrict::Text do
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not report an offense if "\#{bin}/foo" is in a word array' do
|
||||
expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
test do
|
||||
cmd = %W[
|
||||
\#{bin}/foo
|
||||
version
|
||||
]
|
||||
assert_match version.to_s, shell_output(cmd)
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user