Merge pull request #17856 from Homebrew/not-all-bin-interpolation-is-bad

This commit is contained in:
Issy Long 2024-07-25 15:09:38 +01:00 committed by GitHub
commit 928bf87f59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 4 deletions

View File

@ -153,7 +153,7 @@ 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)
ending = bin ? "/| |-|$" : "/| |$"
ending = bin ? "/|-|$" : "/| |$"
path.match?(/^#{Regexp.escape(starts_with)}(#{ending})/)
end

View File

@ -145,12 +145,11 @@ RSpec.describe RuboCop::Cop::FormulaAuditStrict::Text do
RUBY
end
it 'reports an offense if "\#{bin}" is in a `shell_output` string' do
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
it 'does not report an offense if \#{bin}/foo and then a space and more text' do
expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
test do
shell_output("\#{bin}/foo --version")
^^^^^^^^^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `bin/"foo"` instead of `"\#{bin}/foo"`
end
end
RUBY