Interpolated shell_output("#{bin}/foo -v"), for example, is fine
- This would be weird to change because it's a string not a pathname passed to `shell_output`. - I had misunderstood https://github.com/Homebrew/brew/pull/17826#discussion_r1690806375.
This commit is contained in:
parent
b31cfe8a85
commit
38bb463aad
@ -153,7 +153,7 @@ module RuboCop
|
|||||||
# 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.
|
||||||
# If we're checking for "#{bin}", we also check for "-" since similar binaries also don't need interpolation.
|
# 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 ? "/| |-|$" : "/| |$"
|
ending = bin ? "/|-|$" : "/| |$"
|
||||||
path.match?(/^#{Regexp.escape(starts_with)}(#{ending})/)
|
path.match?(/^#{Regexp.escape(starts_with)}(#{ending})/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -145,12 +145,11 @@ RSpec.describe RuboCop::Cop::FormulaAuditStrict::Text do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'reports an offense if "\#{bin}" is in a `shell_output` string' do
|
it 'does not report an offense if \#{bin}/foo and then a space and more text' do
|
||||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
test do
|
test do
|
||||||
shell_output("\#{bin}/foo --version")
|
shell_output("\#{bin}/foo --version")
|
||||||
^^^^^^^^^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `bin/"foo"` instead of `"\#{bin}/foo"`
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user