Class: RuboCop::Cop::Chef::Correctness::PowershellFileExists

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/chef/correctness/powershell_file_exists.rb

Overview

Use Ruby’s built-in ‘File.exist?(’C:somefile’)‘ method instead of executing PowerShell’s ‘Test-Path` cmdlet, which takes longer to load.

Examples:


### incorrect
powershell_out('Test-Path "C:\\Program Files\\LAPS\\CSE\\AdmPwd.dll"').stdout.strip == 'True'

### correct
::File.exist?('C:\Program Files\LAPS\CSE\AdmPwd.dll')

Constant Summary collapse

RESTRICT_ON_SEND =
[:powershell_out, :powershell_out!].freeze
MSG =
"Use Ruby's built-in `File.exist?('C:\\somefile')` method instead of executing PowerShell's `Test-Path` cmdlet, which takes longer to load."

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



40
41
42
43
44
45
# File 'lib/rubocop/cop/chef/correctness/powershell_file_exists.rb', line 40

def on_send(node)
  powershell_out_exists?(node) do |exists_string|
    return unless exists_string.match?(/^Test-Path/)
    add_offense(node, severity: :refactor)
  end
end