Class: RuboCop::Cop::Chef::Modernize::ShellOutHelper

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector, TargetChefVersion
Defined in:
lib/rubocop/cop/chef/modernize/shell_out_helper.rb

Overview

Use the built-in ‘shell_out` helper available in Chef Infra Client 12.11+ instead of calling `Mixlib::ShellOut.new(’foo’).run_command`.

Examples:


### incorrect
Mixlib::ShellOut.new('foo').run_command

### correct
shell_out('foo')

Constant Summary collapse

MSG =
"Use the built-in `shell_out` helper available in Chef Infra Client 12.11+ instead of calling `Mixlib::ShellOut.new('foo').run_command`."
RESTRICT_ON_SEND =
[:run_command].freeze

Instance Method Summary collapse

Methods included from TargetChefVersion

minimum_target_chef_version, required_minimum_chef_version, support_target_chef_version?

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/rubocop/cop/chef/modernize/shell_out_helper.rb', line 49

def on_send(node)
  mixlib_shellout_run_cmd?(node) do |cmd|
    add_offense(node, severity: :refactor) do |corrector|
      corrector.replace(node, "shell_out(#{cmd.source})")
    end
  end
end