Skip to content

Commit

Permalink
Avoid double parentheses for eg. (path/here/).rmtree corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
issyl0 committed Jul 25, 2024
1 parent 429028c commit 25f8a84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Library/Homebrew/rubocops/no_fileutils_rmrf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def on_send(node)
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

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def buildpath
end
buildpath.rmtree
^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
(path/"here").rmtree
^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end

Expand All @@ -76,6 +78,7 @@ def buildpath
Pathname("path/to/yet/another/directory")
end
buildpath.rmtree
(path/"here").rmtree
RUBY

expect(corrected).to eq(<<~RUBY)
Expand All @@ -86,6 +89,7 @@ def buildpath
Pathname("path/to/yet/another/directory")
end
FileUtils.rm_r(buildpath)
FileUtils.rm_r(path/"here")
RUBY
end
end
Expand Down

0 comments on commit 25f8a84

Please sign in to comment.