Skip to content

Report per-file license text coverage - #11

Open
abhinavgautam01 wants to merge 1 commit into
git-pkgs:mainfrom
abhinavgautam01:feat/8-license-text-coverage
Open

Report per-file license text coverage#11
abhinavgautam01 wants to merge 1 commit into
git-pkgs:mainfrom
abhinavgautam01:feat/8-license-text-coverage

Conversation

@abhinavgautam01

Copy link
Copy Markdown

Closes #8

Summary

Add per-file license-text coverage to the scanner's JSON output so consumers can determine whether a file should be treated as complete attribution text.

Each file record now includes:

"license_text_coverage": 95.4

The value is the percentage of decoded file bytes covered by the union of text- and notice-kind match spans.

Implementation

  • Add LicenseTextCoverage to fileRecord
  • Combine overlapping and adjacent match spans without double-counting
  • Include only text and notice matches
  • Ignore reference, tag, introduction, and clue matches
  • Clamp spans to the decoded input bounds
  • Calculate coverage before offsets are remapped to the original encoding
  • Return 0 when no qualifying matches are present

Calculating coverage against decoded bytes keeps the result consistent across UTF-8, UTF-8 BOM, UTF-16LE, UTF-16BE and Latin-1 files.

The JSON schema remains version 1 because this is an additive field and schema 1 already requires consumers to accept unknown fields.

Testing

Added coverage for:

  • Overlapping text and notice spans
  • Exclusion of unrelated match kinds
  • Invalid and out-of-bounds spans
  • Empty and unmatched files
  • UTF-8, UTF-8 BOM, UTF-16LE, UTF-16BE and Latin-1 inputs
  • Presence of license_text_coverage in JSON output

Validation

  • gofmt
  • git diff --check
  • go build ./...
  • go vet ./...
  • go test -count=1 ./...
  • go test -race -count=1 ./...
  • golangci-lint v2.12.2 — 0 issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report per-file licence-text coverage on fileRecord

1 participant