Class: RuboCop::Cop::Chef::Correctness::MetadataMissingVersion

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

Overview

metadata.rb should define a version for the cookbook.

Examples:


### correct
name 'foo'
version '1.0.0'

Constant Summary collapse

MSG =
'metadata.rb should define a version for the cookbook.'

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_new_investigationObject



38
39
40
41
42
43
44
45
46
# File 'lib/rubocop/cop/chef/correctness/metadata_missing_version.rb', line 38

def on_new_investigation
  # handle an empty metdata.rb file
  return if processed_source.ast.nil?

  # Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
  return if cb_version?(processed_source.ast)
  range = source_range(processed_source.buffer, 1, 0)
  add_offense(range, severity: :refactor)
end