class RuboCop::Cop::Chef::Deprecations::UseInlineResourcesDefined

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

@example

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

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/chef/deprecation/use_inline_resources.rb, line 39
def on_send(node)
  # 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, severity: :warning) do |corrector|
    corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
  end
end