Class: RemLint::Rules::LicenseHeader

Inherits:
RemLint::Rule show all
Defined in:
lib/remlint/rules/license_header.rb

Overview

Files missing a licence identifier near the top.

Off by default, because it is a project policy rather than a Remind fact. It exists because it is a policy Remind itself keeps: every file under examples/ carries SPDX-License-Identifier: GPL-2.0-only in its header comment, and a linter is the only thing that keeps that true as files are added.

Pattern is a regular expression as a string, so a project with a different licence or a different marker configures it rather than forking the rule. Only the first WithinLines lines are searched, so a mention halfway down a long file does not count as a header.

Constant Summary collapse

DEFAULT_PATTERN =
"SPDX-License-Identifier:\\s*\\S+"
DEFAULT_WITHIN =
10

Constants inherited from RemLint::Rule

RemLint::Rule::REGISTRY

Instance Attribute Summary

Attributes inherited from RemLint::Rule

#config, #document, #offenses

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemLint::Rule

all, default_severity, find, inherited, #initialize, rule_name, #rule_name, #run

Constructor Details

This class inherits a constructor from RemLint::Rule

Class Method Details

.descriptionObject



27
28
29
# File 'lib/remlint/rules/license_header.rb', line 27

def self.description
  "A licence identifier in the first few lines of the file."
end

.enabled_by_default?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/remlint/rules/license_header.rb', line 23

def self.enabled_by_default?
  false
end

Instance Method Details

#checkObject



31
32
33
34
35
36
37
38
# File 'lib/remlint/rules/license_header.rb', line 31

def check
  within = option("WithinLines", DEFAULT_WITHIN)
  pattern = Regexp.new(option("Pattern", DEFAULT_PATTERN))

  if !document.raw_lines.empty? && !header_matches?(pattern, within)
    offend(document.line_number_at(0), "Missing a licence identifier in the first #{within} lines")
  end
end