Class: RuboCop::Cop::Chef::ChefDeprecations::UseInlineResourcesDefined

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/deprecation/use_inline_resources.rb

Overview

use_inline_resources became the default in Chef Infra Client 13+ and no longer needs to be called in resources

Examples:


# bad
use_inline_resources
use_inline_resources if defined?(use_inline_resources)
use_inline_resources if respond_to?(:use_inline_resources)

Constant Summary collapse

MSG =
'use_inline_resources is now the default for resources in Chef Infra Client 13+ and does not need to be specified.'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



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

def autocorrect(node)
  lambda do |corrector|
    corrector.remove(node.loc.expression)
  end
end

#on_send(node) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rubocop/cop/chef/deprecation/use_inline_resources.rb', line 34

def on_send(node)
  if node.method_name == :use_inline_resources
    # don't alert on the use_inline_resources within the defined? check
    # that would result in 2 alerts on the same line and wouldn't be useful
    return if node.parent && node.parent.defined_type?

    # catch the full offense if the method is gated like this: use_inline_resources if defined?(use_inline_resources)
    if node.parent && node.parent.if_type? && %i(defined? respond_to?).include?(node.parent.children.first.method_name)
      node = node.parent
    end
    add_offense(node, location: :expression, message: MSG, severity: :refactor)
  end
end