Class: RuboCop::Cop::Chef::RedundantCode::DoubleCompileTime

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/redundant/double_compile_time.rb

Overview

If a resource includes the ‘compile_time` property there’s no need to also use ‘.run_action(:some_action)` on the resource block

Examples:


### incorrect
chef_gem 'deep_merge' do
  action :nothing
  compile_time true
end.run_action(:install)

### correct
chef_gem 'deep_merge' do
  action :install
  compile_time true
end

Constant Summary collapse

MSG =
"If a resource includes the `compile_time` property there's no need to also use `.run_action(:some_action)` on the resource block."
RESTRICT_ON_SEND =
[:run_action].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/rubocop/cop/chef/redundant/double_compile_time.rb', line 57

def on_send(node)
  compile_time_and_run_action?(node) do |resource, action, run_action|
    add_offense(node.loc.selector, severity: :refactor) do |corrector|
      corrector.replace(node, resource.source.gsub(action.to_s, run_action.to_s))
    end
  end
end