Class: RuboCop::Cop::Chef::Effortless::SearchForEnvironmentsOrRoles

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/chef/effortless/search_for_environments_or_roles.rb

Overview

Policyfiles (and Effortless) do not use environments or roles so searching for those will need to be refactored before migrating to Policyfiles and the Effortless pattern.

Examples:


### incorrect
search(:node, 'chef_environment:foo')
search(:node, 'role:bar')

Constant Summary collapse

MSG =
'Cookbook uses search with a node query that looks for a role or environment'
RESTRICT_ON_SEND =
[:search].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



34
35
36
37
38
# File 'lib/rubocop/cop/chef/effortless/search_for_environments_or_roles.rb', line 34

def on_send(node)
  if node.arguments[1]&.value&.match?(/chef_environment|role/)
    add_offense(node, severity: :refactor)
  end
end