Class: RuboCop::Cop::Chef::Modernize::ClassEvalActionClass

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector, TargetChefVersion
Defined in:
lib/rubocop/cop/chef/modernize/class_eval_action_class.rb

Overview

In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block.

Examples:


### incorrect
action_class.class_eval do
  foo
end

### correct
action_class do
  foo
end

Constant Summary collapse

MSG =
'In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block.'

Instance Method Summary collapse

Methods included from TargetChefVersion

minimum_target_chef_version, required_minimum_chef_version, support_target_chef_version?

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_block(node) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/rubocop/cop/chef/modernize/class_eval_action_class.rb', line 52

def on_block(node)
  class_eval_action_class?(node) do
    add_offense(node, severity: :refactor) do |corrector|
      corrector.replace(node, node.source.gsub('.class_eval', ''))
    end
  end
end