Fix RuboCop::Cop::FormulaAudit::ShellVariables autocorrect

It used to leave out the parenthesis which could result in invalid
Ruby syntax. Now it always parenthesis here.
This commit is contained in:
apainintheneck 2024-10-17 23:46:40 -07:00
parent ab5f0c0fa5
commit 7aee21ca8b
2 changed files with 5 additions and 6 deletions

View File

@ -338,8 +338,7 @@ module RuboCop
good_args = "Utils.#{command}({ \"#{match[1]}\" => \"#{match[2]}\" }, \"#{match[3]}\")"
problem "Use `#{good_args}` instead of `#{method.source}`" do |corrector|
corrector.replace(@offensive_node.source_range,
"{ \"#{match[1]}\" => \"#{match[2]}\" }, \"#{match[3]}\"")
corrector.replace(method.source_range, good_args)
end
end
end

View File

@ -19,7 +19,7 @@ RSpec.describe RuboCop::Cop::FormulaAudit::ShellVariables do
expect_correction(<<~RUBY)
class Foo < Formula
def install
Utils.popen { "SHELL" => "bash" }, "foo"
Utils.popen({ "SHELL" => "bash" }, "foo")
end
end
RUBY
@ -38,7 +38,7 @@ RSpec.describe RuboCop::Cop::FormulaAudit::ShellVariables do
expect_correction(<<~RUBY)
class Foo < Formula
def install
Utils.safe_popen_read { "SHELL" => "bash" }, "foo"
Utils.safe_popen_read({ "SHELL" => "bash" }, "foo")
end
end
RUBY
@ -57,7 +57,7 @@ RSpec.describe RuboCop::Cop::FormulaAudit::ShellVariables do
expect_correction(<<~RUBY)
class Foo < Formula
def install
Utils.safe_popen_write { "SHELL" => "bash" }, "foo"
Utils.safe_popen_write({ "SHELL" => "bash" }, "foo")
end
end
RUBY
@ -76,7 +76,7 @@ RSpec.describe RuboCop::Cop::FormulaAudit::ShellVariables do
expect_correction(<<~RUBY)
class Foo < Formula
def install
Utils.popen { "SHELL" => "bash" }, "\#{bin}/foo"
Utils.popen({ "SHELL" => "bash" }, "\#{bin}/foo")
end
end
RUBY