Class: RuboCop::Cop::Homebrew::NoFileutilsRmrf Private
- Extended by:
- AutoCorrector
- Defined in:
- rubocops/no_fileutils_rmrf.rb,
sorbet/rbi/dsl/rubo_cop/cop/homebrew/no_fileutils_rmrf.rbi
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
This cop checks for the use of FileUtils.rm_f
, FileUtils.rm_rf
, or {FileUtils,instance}.rmtree
and recommends the safer versions.
Constant Summary collapse
- MSG =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"Use `rm` or `rm_r` instead of `rm_rf`, `rm_f`, or `rmtree`."
Instance Method Summary collapse
- #any_receiver_rm_r_f?(node, **kwargs, &block) ⇒ T.untyped private
- #any_receiver_rmtree?(node, **kwargs, &block) ⇒ T.untyped private
- #neither_rm_rf_nor_rmtree?(node) ⇒ Boolean private
- #no_receiver_rm_r_f?(node, **kwargs, &block) ⇒ T.untyped private
- #no_receiver_rmtree?(node, **kwargs, &block) ⇒ T.untyped private
- #on_send(node) ⇒ Object private
Instance Method Details
#any_receiver_rm_r_f?(node, **kwargs, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 |
# File 'sorbet/rbi/dsl/rubo_cop/cop/homebrew/no_fileutils_rmrf.rbi', line 10 def any_receiver_rm_r_f?(node, **kwargs, &block); end |
#any_receiver_rmtree?(node, **kwargs, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
13 |
# File 'sorbet/rbi/dsl/rubo_cop/cop/homebrew/no_fileutils_rmrf.rbi', line 13 def any_receiver_rmtree?(node, **kwargs, &block); end |
#neither_rm_rf_nor_rmtree?(node) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
54 55 56 57 |
# File 'rubocops/no_fileutils_rmrf.rb', line 54 def neither_rm_rf_nor_rmtree?(node) !any_receiver_rm_r_f?(node) && !no_receiver_rm_r_f?(node) && !any_receiver_rmtree?(node) && !no_receiver_rmtree?(node) end |
#no_receiver_rm_r_f?(node, **kwargs, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
16 |
# File 'sorbet/rbi/dsl/rubo_cop/cop/homebrew/no_fileutils_rmrf.rbi', line 16 def no_receiver_rm_r_f?(node, **kwargs, &block); end |
#no_receiver_rmtree?(node, **kwargs, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
19 |
# File 'sorbet/rbi/dsl/rubo_cop/cop/homebrew/no_fileutils_rmrf.rbi', line 19 def no_receiver_rmtree?(node, **kwargs, &block); end |
#on_send(node) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'rubocops/no_fileutils_rmrf.rb', line 33 def on_send(node) return if neither_rm_rf_nor_rmtree?(node) add_offense(node) do |corrector| class_name = "FileUtils." if any_receiver_rm_r_f?(node) || any_receiver_rmtree?(node) new_method = if node.method?(:rm_rf) || node.method?(:rmtree) "rm_r" else "rm" end args = if any_receiver_rmtree?(node) node.receiver&.source || node.arguments.first&.source else node.arguments.first.source end args = "(#{args})" unless args.start_with?("(") corrector.replace(node.loc.expression, "#{class_name}#{new_method}#{args}") end end |