Avoid double parentheses for eg. (path/here/).rmtree corrections

This commit is contained in:
Issy Long 2024-07-15 15:09:55 -04:00
parent 7404735654
commit 0872966c27
No known key found for this signature in database
2 changed files with 6 additions and 2 deletions

View File

@ -46,8 +46,8 @@ module RuboCop
else
node.arguments.first.source
end
corrector.replace(node.loc.expression, "#{class_name}#{new_method}(#{args})")
args = "(#{args})" unless args.start_with?("(")
corrector.replace(node.loc.expression, "#{class_name}#{new_method}#{args}")
end
end

View File

@ -64,6 +64,8 @@ RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do
end
buildpath.rmtree
^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
(path/"here").rmtree
^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end
@ -76,6 +78,7 @@ RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do
Pathname("path/to/yet/another/directory")
end
buildpath.rmtree
(path/"here").rmtree
RUBY
expect(corrected).to eq(<<~RUBY)
@ -86,6 +89,7 @@ RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do
Pathname("path/to/yet/another/directory")
end
FileUtils.rm_r(buildpath)
FileUtils.rm_r(path/"here")
RUBY
end
end