class RuboCop::Cop::Chef::RedundantCode::StringPropertyWithNilDefault

Properties have a nil value by default so there is no need to set the default value to nil.

@example

#### incorrect
property :config_file, String, default: nil
property :config_file, [String, NilClass], default: nil

#### correct
property :config_file, String
property :config_file, [String, NilClass]

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/chef/redundant/string_property_with_nil_default.rb, line 52
def on_send(node)
  string_property_with_nil_default?(node) do |nil_default|
    add_offense(nil_default, message: MSG, severity: :refactor) do |corrector|
      range = range_with_surrounding_comma(range_with_surrounding_space(range: nil_default.loc.expression, side: :left), :left)
      corrector.remove(range)
    end
  end
end