Class: RuboCop::Cop::Chef::Sharing::EmptyPropertyDescription

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/chef/sharing/empty_property_description.rb

Overview

Resource properties should not set an empty description. Automated documentation tools have nothing to render from it, so it does no more than a missing field would while looking like the property has been documented.

Examples:


# bad
property :site_name, String,
         name_property: true,
         description: ''

# good
property :site_name, String,
         name_property: true,
         description: 'The name of the site'

Constant Summary collapse

MSG =
'Resource properties should not set an empty `description`. Either describe the property or leave the field off entirely.'
RESTRICT_ON_SEND =
[:property].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/cop/chef/sharing/empty_property_description.rb', line 47

def on_send(node)
  property_options(node) do |options|
    options.pairs.each do |pair|
      next unless pair.key.sym_type? && pair.key.value == :description
      # a description built by interpolation isn't a literal str node, so we can't tell
      # whether it's empty and leave it alone
      next unless pair.value.str_type? && pair.value.value.strip.empty?
      add_offense(pair, severity: :refactor)
    end
  end
end