Class: RuboCop::Cop::Chef::Correctness::ScopedFileExist

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/correctness/scoped_file_exist.rb

Overview

Scope file exist to access the correct ‘File` class by using `::File.exist?` not `File.exist?`.

Examples:


### incorrect
not_if { File.exist?('/etc/foo/bar') }

### correct
not_if { ::File.exist?('/etc/foo/bar') }

Constant Summary collapse

MSG =
'Scope file exist to access the correct File class by using ::File.exist? not File.exist?.'

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_block(node) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/rubocop/cop/chef/correctness/scoped_file_exist.rb', line 41

def on_block(node)
  unscoped_file_exist?(node) do |m|
    add_offense(m, severity: :refactor) do |corrector|
      corrector.replace(m, '::File')
    end
  end
end