Class: RuboCop::Cop::Chef::ChefCorrectness::ResourceWithNoneAction

Inherits:
RuboCop::Cop
  • Object
show all
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/correctness/resource_with_none_action.rb

Overview

The :nothing action is often typo’d as :none

Examples:


# bad
service 'foo' do
 action :none
end

# good
service 'foo' do
 action :nothing
end

Constant Summary collapse

MSG =
'Resource uses the nonexistent :none action instead of the :nothing action'.freeze

Instance Method Summary collapse

Methods included from RuboCop::Chef::CookbookHelpers

#match_property_in_resource?, #match_resource_type?, #method_arg_ast_to_string, #resource_block_name_if_string

Instance Method Details

#on_block(node) ⇒ Object



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

def on_block(node)
  match_property_in_resource?(nil, 'action', node) do |action_node|
    action_node.arguments.each do |action|
      add_offense(action, location: :expression, message: MSG, severity: :refactor) if action.source == ':none'
    end
  end
end