Class: RuboCop::Cop::Chef::Style::CopyrightCommentFormat

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/style/comments_copyright_format.rb

Overview

Checks for incorrectly formatted copyright comments.

Examples:


### incorrect
Copyright:: 2013-2022 Opscode, Inc.
Copyright:: 2013-2022 Chef Inc.
Copyright:: 2013-2022 Chef Software Inc.
Copyright:: 2009-2010 2013-2022 Chef Software Inc.
Copyright:: Chef Software Inc.
Copyright:: Tim Smith
Copyright:: Copyright (c) 2015-2022 Chef Software, Inc.

### correct
Copyright:: 2013-2022 Chef Software, Inc.
Copyright:: 2013-2022 Tim Smith
Copyright:: 2019 37Signals, Inc.

Constant Summary collapse

MSG =
'Properly format copyrights header comments'

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_new_investigationObject



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

def on_new_investigation
  return unless processed_source.ast

  processed_source.comments.each do |comment|
    next unless comment.inline? && invalid_copyright_comment?(comment) # headers aren't in blocks

    add_offense(comment, severity: :refactor) do |corrector|
      correct_comment = "# Copyright:: #{copyright_date_range(comment)}, #{copyright_holder(comment)}"
      corrector.replace(comment, correct_comment)
    end
  end
end