Class: RuboCop::Cop::Chef::Deprecations::PowershellCookbookHelpers

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

Overview

Use ‘node[’version’]‘ or the new `powershell_version` helper available in Chef Infra Client 15.8+ instead of the deprecated PowerShell cookbook helpers

Examples:


### incorrect
Powershell::VersionHelper.powershell_version?('4.0')

### correct
node['powershell']['version'].to_f == 4.0

# better (Chef Infra Client 15.8+)
powershell_version == 4.0

Constant Summary collapse

MSG =
"Use node['powershell']['version'] or the new powershell_version helper available in Chef Infra Client 15.8+ instead of the deprecated PowerShell cookbook helpers."
RESTRICT_ON_SEND =
[:powershell_version?].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb', line 48

def on_send(node)
  ps_cb_helper?(node) do |ver|
    add_offense(node, severity: :warning) do |corrector|
      corrector.replace(node, "node['powershell']['version'].to_f == #{ver.source}")
    end
  end
end