Class: RuboCop::Cop::Chef::Correctness::PropertyWithoutType

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

Overview

Resource properties or attributes should always define a type to help users understand the correct allowed values.

Examples:


### incorrect
property :size, regex: /^\d+[KMGTP]$/
attribute :size, regex: /^\d+[KMGTP]$/

### correct
property :size, String, regex: /^\d+[KMGTP]$/
attribute :size, kind_of: String, regex: /^\d+[KMGTP]$/

Constant Summary collapse

MSG =
'Resource properties or attributes should always define a type to help users understand the correct allowed values.'
RESTRICT_ON_SEND =
[:property, :attribute].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/rubocop/cop/chef/correctness/property_without_type.rb', line 48

def on_send(node)
  property_without_type?(node) do |hash_vals|
    return if hash_vals&.first&.keys&.include?(s(:sym, :kind_of))

    add_offense(node, severity: :refactor)
  end
end