Class: RuboCop::Cop::Chef::RedundantCode::UnnecessaryDesiredState

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

Overview

There is no need to set a property/attribute to desired_state: true as all properties/attributes have a desired_state of true by default.

Examples:


### incorrect
property :foo, String, desired_state: true
attribute :foo, String, desired_state: true

### correct
property :foo, String
attribute :foo, String

Constant Summary collapse

MSG =
'There is no need to set a property to desired_state: true as all properties have a desired_state of true by default.'
RESTRICT_ON_SEND =
[:property, :attribute].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb', line 45

def on_send(node)
  property?(node) do |hash_vals|
    hash_vals.each_pair do |k, v|
      next unless k == s(:sym, :desired_state) && v == s(:true) # cookstyle: disable Lint/BooleanSymbol
      add_offense(v.parent, severity: :refactor) do |corrector|
        range = range_with_surrounding_comma(range_with_surrounding_space(range: v.parent.loc.expression, side: :left), :left)
        corrector.remove(range)
      end
    end
  end
end