Class: RuboCop::Cop::Chef::Deprecations::ChefShellout

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

Overview

Don’t use the deprecated ‘Chef::ShellOut` class which was removed in Chef Infra Client 13. Use the `Mixlib::ShellOut` class instead, which behaves identically or convert to the simpler `shell_out` helper.

Examples:


### incorrect
include Chef::ShellOut
require 'chef/shellout'
Chef::ShellOut.new('some_command')

### correct
include Mixlib::ShellOut
require 'mixlib/shellout'
Mixlib::ShellOut.new('some_command')

Constant Summary collapse

MSG =
"Don't use the deprecated `Chef::ShellOut` class which was removed in Chef Infra Client 13. Use the `Mixlib::ShellOut` class instead, which behaves identically."
RESTRICT_ON_SEND =
[:new, :require, :include].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rubocop/cop/chef/deprecation/chef_shellout.rb', line 60

def on_send(node)
  include_shellout?(node) do
    add_offense(node, severity: :warning) do |corrector|
      corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
    end
  end

  require_shellout?(node) do
    add_offense(node, severity: :warning) do |corrector|
      corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
    end
  end

  shellout_new?(node) do
    add_offense(node, severity: :warning) do |corrector|
      corrector.replace(node, node.source.gsub('Chef::ShellOut', 'Mixlib::ShellOut'))
    end
  end
end