From 25f8a847faa5bd76b94578b8c5cb0bb853e0a768 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Mon, 15 Jul 2024 15:09:55 -0400 Subject: [PATCH] Avoid double parentheses for eg. `(path/here/).rmtree` corrections --- Library/Homebrew/rubocops/no_fileutils_rmrf.rb | 4 ++-- Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/rubocops/no_fileutils_rmrf.rb b/Library/Homebrew/rubocops/no_fileutils_rmrf.rb index 9828d12c306a4..b1e22cf30f9f9 100644 --- a/Library/Homebrew/rubocops/no_fileutils_rmrf.rb +++ b/Library/Homebrew/rubocops/no_fileutils_rmrf.rb @@ -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 diff --git a/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb b/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb index 128d3bd3e5b75..bc8b4aa99f6fa 100644 --- a/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb +++ b/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb @@ -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 @@ -76,6 +78,7 @@ def buildpath Pathname("path/to/yet/another/directory") end buildpath.rmtree + (path/"here").rmtree RUBY expect(corrected).to eq(<<~RUBY) @@ -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