Skip to content

Expose structured per-field diff/issues, not just raw before/after header text #34

Description

@Shinrai

Problem

sampleOutput: true currently gives consumers, per changed file (src/core/fix-headers.mjs's FixHeadersResult.changes[].sample):

  • previousValue / newValue — the full header text blob, before and after
  • detectedValues — the resolved fields fix-headers computed (authorName, authorEmail, companyName, copyrightStartYear, createdAt/lastModifiedAt, etc.)

There's no field-level comparison anywhere — changed is a single boolean rolled up across the whole header, and detectedValues only shows the new resolved values with nothing to say what the previous header actually had per field, or which specific field(s) differed.

This surfaced while onboarding @cldmv/droidsock's tools/fix-headers.mjs CLI wrapper: it advertised --verbose ("show per-file issue details") and --diff ("show unified diff output"), neither of which it actually implemented — both flags just print the list of changed filenames. Looking at what the library exposes, there's no reasonable way for a consumer to build either feature properly:

  • A diff could technically be hand-rolled by a consumer running a diff algorithm over previousValue/newValue, but that's reinventing the same computation in every consumer of a tool whose entire job is comparing old-vs-new header text. It belongs in the library that already holds both strings.
  • Per-file issue details (e.g. "author differs: found X, expected Y", "copyright year stale") can't be built by a consumer at all — there's no structured previous-vs-detected comparison to reconstruct without re-parsing previousValue and guessing which text corresponds to which field.

Ask

Extend FixHeadersResult.changes[].sample (behind the existing sampleOutput option, so it stays opt-in/zero-cost by default) with:

  1. A ready-to-print unified diff string (previousValue vs newValue), so consumers don't each need their own diff dependency for this.
  2. A structured per-field issues list, e.g. { field: "authorName", previous: "Foo", detected: "Bar" }[] — the comparison logic in fix-headers.mjs around comparisonReplacement/needsUpdate (src/core/fix-headers.mjs:~325) already has both the existing-header parse and the newly-detected values in scope at the point it decides changed; this would be surfacing that existing internal comparison rather than computing something new.

Why here and not in the consumer

Filed against fix-headers rather than fixed in droidsock's wrapper: the raw data needed to build a real diff/per-field breakdown either already exists internally (previous vs. detected per field, at decision time) or is squarely this library's own domain (diffing header text it authored). A consumer-side workaround would either duplicate that internal comparison via fragile text-diffing, or require running a hand-rolled diff algorithm.

Activity

  1. added
    priority: low
    type: feature request
    area: core
    on Aug 31, 2026
  2. added
    status: not started
    on Sep 27, 2026
  3. added theissue type on Sep 27, 2026
  4. Shinrai commented on Sep 27, 2026

    @Shinrai
    ContributorAuthor

    Triage note: not implemented yet. The per-field half is a bit bigger than "surface an existing comparison" — the current code (src/core/fix-headers.mjs) only parses the author identity, last-modified identity, @Date and @Last modified time out of the existing header. Project name, company and copyright year aren't parsed back, so those fields need new extractors. Also, the author/last-modified fields preserve the existing value unless forced, so they won't show "found X, expected Y" in a normal run.

    Open decision for the unified diff: pull in a runtime diff dependency (fix-headers currently depends only on ignore) or hand-roll a small line-level diff for the header block.

  5. added
    status: in progress
    and removed
    status: not started
    on Sep 28, 2026
  6. Shinrai commented on Sep 28, 2026

    @Shinrai
    ContributorAuthor

    Implementation started on feat/sample-field-diff (off next). The open decision is settled as a hand-rolled line-level diff of the header block, so ignore stays the only runtime dependency.

    Behind sampleOutput only:

    • sample.diff: a unified diff (---/+++/@@) of the previous vs new header; a file with no previous header shows the whole new header as added.
    • sample.issues: { field, previous, detected }[] for every header field whose written value differs from the existing one, with new extractors for project name, company and copyright. Author and last-modified identity are compared against what is actually written, so they only appear when they really change (i.e. when forced).
    • CLI: --diff prints each changed file's diff; --verbose --sample-output prints the per-field issues.
  7. added
    status: implemented
    and removed
    status: in progress
    on Sep 28, 2026
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

    area: corepriority: lowstatus: implementedtype: feature request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions