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 =

Returns Regex matching valid SPDX license identifier lines.

Returns:

  • (Regexp)

    Regex matching valid SPDX license identifier lines.

/SPDX-License-Identifier:/
HEADER_SCAN_LINES =

Returns Number of lines to scan for SPDX headers.

Returns:

  • (Integer)

    Number of lines to scan for SPDX headers.

10
SOURCE_GLOBS =

Returns Glob patterns for source files requiring SPDX headers.

Returns:

  • (Array)

    Glob patterns for source files requiring SPDX headers.

[
  '**/*.rb',
  '**/*.yml',
  '**/*.yaml',
  '**/*.sh'
].freeze
SKIP_DIRS =

Returns Directory names excluded from SPDX header scanning.

Returns:

  • (Array)

    Directory names excluded from SPDX header scanning.

[
  '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



42
43
44
45
# File 'lib/rosett_ai/comply/checkers/spdx_header_checker.rb', line 42

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



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rosett_ai/comply/checkers/spdx_header_checker.rb', line 50

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