class RuboCop::Cop::Chef::Correctness::PowershellFileExists

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

@example

#### 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')

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# 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