Class: RuboCop::Cop::Chef::Modernize::ConditionalUsingTest
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chef/modernize/conditional_using_test.rb
Overview
Use ::File.exist?(‘/foo/bar’) instead of the slower ‘test -f /foo/bar’ which requires shelling out
Constant Summary collapse
- MSG =
"Use ::File.exist?('/foo/bar') instead of the slower 'test -f /foo/bar' which requires shelling out"
- RESTRICT_ON_SEND =
[:not_if, :only_if].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/rubocop/cop/chef/modernize/conditional_using_test.rb', line 42 def on_send(node) resource_conditional?(node) do |conditional| return unless conditional.value.match?(/^test -[ef] \S*$/) add_offense(node, severity: :refactor) do |corrector| new_string = "{ ::File.exist?('#{conditional.value.match(/^test -[ef] (\S*)$/)[1]}') }" corrector.replace(conditional, new_string) end end end |