Class: RuboCop::Cop::Chef::Modernize::IncludingMixinShelloutInResources

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

Overview

There is no need to include Chef::Mixin::ShellOut or Chef::Mixin::PowershellOut in resources or providers as this is already done by Chef Infra Client 12.4+.

Examples:


### incorrect
require 'chef/mixin/shell_out'
include Chef::Mixin::ShellOut
require 'chef/mixin/powershell_out'
include Chef::Mixin::PowershellOut

Constant Summary collapse

MSG =
'There is no need to include Chef::Mixin::ShellOut or Chef::Mixin::PowershellOut in resources or providers as this is already done by Chef Infra Client 12.4+.'
RESTRICT_ON_SEND =
[:include, :require].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#check_for_offenses(node) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb', line 59

def check_for_offenses(node)
  containing_dir = File.basename(File.dirname(processed_source.path))

  # only add offenses when we're in a custom resource or HWRP, but not a plain old library
  if containing_dir == 'resources' || hwrp_classes?(processed_source.ast)
    add_offense(node, severity: :refactor) do |corrector|
      corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
    end
  end
end

#on_send(node) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb', line 70

def on_send(node)
  require_shellout?(node) do
    check_for_offenses(node)
  end

  include_shellout?(node) do
    check_for_offenses(node)
  end
end