Class: RuboCop::Cop::Chef::ChefCorrectness::CookbooksDependsOnSelf

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

Constant Summary collapse

MSG =
'A cookbook cannot depend on itself. This will fail on Chef Infra Client 13+'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



50
51
52
53
54
# File 'lib/rubocop/cop/chef/correctness/cb_depends_on_self.rb', line 50

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

#on_send(node) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/rubocop/cop/chef/correctness/cb_depends_on_self.rb', line 39

def on_send(node)
  cb_name?(node) do
    dependencies(processed_source.ast).each do |dep|
      if dep.arguments == node.arguments
        node = dep # set our dependency node as the node for autocorrecting later
        add_offense(node, location: dep.source_range, message: MSG, severity: :refactor)
      end
    end
  end
end