Class: RuboCop::Cop::Elegant::SpdxOnTop

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/elegant/spdx_on_top.rb

Overview

Requires the SPDX header to sit above the code. The header is the license declaration of the file, and REUSE keeps it in the first few lines so that scanners, editors and reviewers read the license without parsing past unrelated code. Only blank lines and comments may precede it: a shebang, a magic comment, a RuboCop directive. A file that carries no SPDX comment at all is left alone, because checking that the tags exist is the job of reuse lint and not of this plugin. Only the first SPDX comment counts, so the tags of a multi-line header may be split by nothing but comments.

Constant Summary collapse

MSG =
'SPDX header must be above the code, but this line comes before it'

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



19
20
21
22
23
24
25
# File 'lib/rubocop/cop/elegant/spdx_on_top.rb', line 19

def on_new_investigation
  header = spdx
  return if header.nil?
  line = intruder(header.location.line)
  return if line.nil?
  add_offense(processed_source.buffer.line_range(line))
end