Skip to content

star lint copyright's checker is looser than its fixer's pattern, so the defects it misses can never be fixed #997

Open

Description

@David-Noble-at-work

star lint copyright's checker is far looser than the pattern its fixer writes, and because the fixer only runs
on files the checker flags, the correct fix is unreachable for every defect the checker cannot see.

check_result = check_file(f, license, holder)
if check_result["skipped"] or check_result["ok"]:
    continue
fix_result = fix_file(f, license, holder)

check_file is the gate on fix_file. Anything it calls ok is never normalized, however far from the pattern
it sits.

The pattern

One function defines it, build_expected_header at
cmd/star/extensions/com.noblefactor.star.LintCopyright/commands/lint-copyright.star:118:

<comment> SPDX-License-Identifier: <license>
<comment> Copyright <holder>. All rights reserved.

Two lines, adjacent, in that order, comment prefix by extension. With license: auto resolving to Apache-2.0
and holder: Noble Factor from star/config.yaml, the canonical Go header is:

// SPDX-License-Identifier: Apache-2.0
// Copyright Noble Factor. All rights reserved.

No year, no (c), no LLC.

What the checker lets through

Header Checker Ever fixed?
no blank line before package — the license becomes the package doc comment passes no
# Copyright 2025-2026 Noble Factor LLC — as in star/config.yaml itself passes no
# Copyright (c) 2026 Noble Factor. All rights reserved. — as in the PR scripts passes no
//SPDX-License-Identifier:Apache-2.0 with no spaces anywhere passes no
missing, or a holder not containing "Noble Factor" fails yes, correctly

Three variants of the copyright line are live in this organization's files and all three pass, because the only
assertion is holder not in found_holder — a substring test. \s* in both patterns makes the spacing after the
comment marker free.

The blank line is the one that carries meaning. check_file reads lines[start_line] and
lines[start_line + 1], matches two regexes and returns; nothing looks at what follows. In Go a comment block
immediately above package is the package doc comment, so go doc would print the license as the package's
documentation. The blank line is what makes it a plain file header.

Measured 2026-09-30: 0 tracked .go files are in that state. The blank line is present everywhere, by
convention and gofmt habit rather than because anything checks it. So this is a hole in the gate, not damage
in the tree — it stays a hole until a file slips through it.

Where the fixer over-reaches

fix_file writes shebang + header + "\n\n" + rest after stripping leading blanks, which is correct — exactly
one blank line. But shebang = lines[0] + "\n\n" always inserts a blank line between a shebang and the SPDX
line, and check_file accepts a shebang with or without one. Our .ps1 scripts carry SPDX on line 2 with no
blank, so the fixer would rewrite a conforming file. It can only trigger when something else in the header is
already wrong, so it is over-reach rather than damage.

fix_file's header-detection loop scans min(start_line + 5, len(lines)) lines. The bound has no stated
reason and silently mis-handles any file with a longer leading comment block.

Evidence of completion

  • check_file asserts a blank line follows the header, and a fixture with the header directly above
    package fails.
  • check_file asserts the canonical copyright line rather than a substring, so the three live variants
    converge on one. The files carrying the other two are updated in the same change, star/config.yaml
    among them.
  • check_file and fix_file agree about the shebang blank line; one of them changes, and a .ps1
    fixture pins whichever way it goes.
  • The + 5 scan window is given a reason or a bound that cannot mis-handle a long leading comment block.
  • A fixture that passes the checker but differs from build_expected_header is added, and the test
    asserts there is no such file — check and fix describe the same pattern.

Related documents

Document What it is
lint-copyright.star The checker, the fixer, and build_expected_header
devlore-cli#994 go-style --fix merges the two header lines into one; this checker is what would catch it, and the regression test belongs here
devlore-cli#964 CI lints neither Markdown, PowerShell, Go style nor copyright; copyright is the one of the four that passes today
star/config.yaml lint.copyright settings, and itself one of the files carrying a non-canonical header

Activity

  1. David-Noble-at-work commented on Oct 1, 2026

    @David-Noble-at-work
    ContributorAuthor

    Resolved by a simpler design than this issue proposed, 2026-10-01

    The divergence is real and the fix is not a tighter checker. The header becomes a literal string in
    configuration
    , so there is nothing left to pattern-match and SPDX_PATTERN and COPYRIGHT_PATTERN are
    deleted rather than tightened.

    lint:
      copyright:
        header: |
          SPDX-License-Identifier: Apache-2.0
          Copyright (c) 2025 Noble Factor. All rights reserved.

    check compares a file's leading lines to that string with the comment prefix applied; fix writes the same
    string. They cannot disagree, because there is one string. That is stronger than the property this issue asked
    for, which was that they agree.

    Ruled while designing it:

    check_file should be setup to ensure check_file requires exactly what fix_file produces.

    The headers are configuration, not code. I should be reading config.

    No template fields. An earlier design had a Go template with {{.Year}}, {{.Holder}} and {{.License}}.
    All three were struck: the year needs a clock no provider exposes, Holder substitutes one configured string
    into another, and the license identifier is typed into the header where a reader can see it. license: auto,
    detect_license, LICENSE_PATTERNS, resolve_license and the holder key are deleted with them -- and with
    them a fourth substring match of exactly this issue's kind, if LICENSE_PATTERNS[spdx_id] in content.

    The four disagreements, and what closes each

    Disagreement Closed by
    blank line before the code check requires it. In Go a comment block immediately above package IS the package doc comment, so this rule changes meaning, not appearance
    the copyright line, matched as a substring gone -- the comparison is against the configured literal
    spacing after the comment marker gone -- same reason
    blank line after a shebang skip per language, so the header follows the skipped line. This is the kernel's own rule: the identifier goes on "the first line that can contain a comment," line two in a script

    The + 5 scan window is replaced by detect, a per-language pattern matching a line of a header already
    present, so fix knows what to replace rather than assuming every leading comment line is part of it.

    What the fixer's reachability means, and it still matters

    fix_file runs only on files check_file flags, so the checker is the gate on the fixer and every defect the
    checker cannot see is permanently unfixable. A literal header closes that by construction, but the acceptance
    is still written as a property rather than a list of cases, because the coupling is the reason the four
    disagreements above were invisible rather than merely wrong.

    Performance, measured, and the conclusion reversed

    This issue also carried the 39 fruitless walks. Measured 2026-09-30/10-01: 4.3 s warm with 39 walks, 1.1 s
    with four
    , over the same 1,001 files -- so the cost was discovery, not the checking, and deleting 35 dict
    entries recovers it. An earlier draft concluded the sweep should move into a Go provider method. That is
    withdrawn
    : there is no performance case for Go here, and the rule the codebase follows is narrower --
    lint.starlark is in Go because it resolves calls against op.ReceiverRegistry(), which Starlark cannot see.
    Comparing two lines of text is not that.

    The diagnostic changes as a consequence: Wrong license: expected Apache-2.0, found MIT becomes a difference
    against the configured header. Less specific, more actionable, and it cannot go stale as the header changes.

    Tracked in #994's plan,
    Requirements 3, 4 and 6, Phases 3 and 4.

  2. David-Noble-at-work commented on Oct 1, 2026

    @David-Noble-at-work
    ContributorAuthor

    Addendum: identification is a lookup, and the work happens in one pass

    Two refinements to the performance half of this issue, both from review after the earlier comment.

    The table is inverted into lookups once, before the walk. Deleting the 34 fruitless walks fixes discovery,
    but it leaves identification: asking "what language is this file" by scanning every language and every pattern,
    with each glob compiled on every comparison. A thousand files over nine languages is tens of thousands of
    string operations, and the broad default table a shipped builtin wants makes it hundreds of thousands. So
    by_extension and by_filename become dictionaries and the globs are compiled once, leaving only the glob
    and shebang paths linear -- and both are reached rarely.

    The first draft of the fix did the linear version and read as compliant, because "walk once and decide per
    entry" conceals what deciding costs.

    The checking and repairing happen in the reducer, in that same pass. An earlier draft walked the tree to
    build a list of (path, language) pairs and then iterated it. Two defenses were offered for the second pass
    and both were wrong:

    • --fix writing into the tree it is walking is a hazard. It is not. --fix rewrites a file's contents and
      adds, removes or renames no directory entry, so the walk's view does not change under it. The
      modify-while-walking hazard concerns entries changing, not bytes changing.
    • A sort is needed for deterministic output. It is not. The provider walks over fs.WalkDir, which Go
      documents as walking in lexical order, so the ordering was already stable and the sort was redundant.

    The single pass costs the count up front -- the report moves to the end, since the number of files is unknown
    until the walk finishes. That is the whole price.

    Two costs accepted rather than removed, recorded so neither looks like an oversight later:

    • The walk filters rather than prunes. A Starlark reducer returns an accumulator, not an error, and
      file.SkipDir exists in Go but is not exposed to Starlark -- so the walker descends into an excluded
      directory and the reducer rejects what it finds. 82 of devlore-cli's 1,542 in-scope files sit under
      testdata, so the waste is small. True pruning needs SkipDir reachable from a Starlark reducer, which is
      a provider change and not this issue's.
    • The shebang path reads a file, so it is consulted only for a path with no extension and only after the
      filename, extension and glob lookups all miss -- about twenty files across the three repositories rather
      than every font and image in the tree.
  3. David-Noble-at-work commented on Nov 9, 2026

    @David-Noble-at-work
    ContributorAuthor

    star github triage sweep added this issue to Triage: devlore, for the rule it breaks:

    • severity: a Bug whose Severity is blank; a bug is Critical, High, Medium or Low
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions