Class: RosettAi::Comply::Checkers::SpdxHeaderChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/comply/checkers/spdx_header_checker.rb

Overview

SPDX license header compliance checker.

Verifies that all source files contain proper SPDX-License-Identifier headers. Supports Ruby, YAML, JSON, Bash, and Markdown files.

Author:

  • hugo

  • claude

Constant Summary collapse

SPDX_PATTERN =
/SPDX-License-Identifier:/
HEADER_SCAN_LINES =
10
SOURCE_GLOBS =
[
  '**/*.rb',
  '**/*.yml',
  '**/*.yaml',
  '**/*.sh'
].freeze
SKIP_DIRS =
[
  'vendor',
  'node_modules',
  'tmp',
  'coverage',
  'pkg',
  '.git'
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(project_root:, expected_spdx: 'GPL-3.0-only') ⇒ SpdxHeaderChecker

Returns a new instance of SpdxHeaderChecker.

Parameters:

  • project_root (Pathname)

    project root directory

  • expected_spdx (String) (defaults to: 'GPL-3.0-only')

    expected SPDX identifier



38
39
40
41
# File 'lib/rosett_ai/comply/checkers/spdx_header_checker.rb', line 38

def initialize(project_root:, expected_spdx: 'GPL-3.0-only')
  @project_root = project_root
  @expected_spdx = expected_spdx
end

Instance Method Details

#checkArray<Hash>

Runs SPDX header compliance check.

Returns:

  • (Array<Hash>)

    check results



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rosett_ai/comply/checkers/spdx_header_checker.rb', line 46

def check
  files = discover_source_files
  return [pass_result_no_files] if files.empty?

  missing = files.reject { |path| spdx_header?(path) }

  if missing.empty?
    [pass_result(files.size)]
  else
    [warn_result(missing, files.size)]
  end
end