Skip to content

chore(eslint): report provenance in source comments, with a baseline of current sites - #9516

Merged
cixzhang merged 4 commits into
mainfrom
lint/no-comment-provenance
Nov 2, 2026
Merged

cixzhang merged 4 commits into
mainfrom
lint/no-comment-provenance

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

The repository's comment rule (the "Source comments" rule in docs/architecture/knowledge-contracts.md and the AGENTS.md comment rule) says a source comment explains only non-obvious work and never cites a record, a claim, a pull request, an issue, or a date. Nothing checks it, so new citations keep landing next to the existing ones. Each one goes stale when the record or the code moves, and readers follow it instead of pnpm specs:for <path>.

Intended invariant

New comments in shipped package source carry no provenance. Existing sites stay allowed through a baseline, the same mechanism as no-raw-private-attribute and no-truthy-jsx-guard, and the baseline only shrinks.

Change

Adds @astryx/no-comment-provenance to the internal ESLint plugin and turns it on for packages/*/src (no tests, stories, or fixtures) at the strict-mode severity, with a baseline of every current site.

It reads comments only, never strings, and reports:

  • record ids (spec:AST-…, component:…, module:…, architecture:…, family:…, design:…, theme:…, bare AST-NNN) and claim ids with a known prefix (FR, INV, DEC, AR, DR, …), using the id grammar that check:knowledge reads;
  • pull request and issue references (#1234, PR #77, GitHub pull/issue URLs). A bare # number with 3, 6, or 8 digits can be a hex colour, so it is skipped;
  • date stamps (an unquoted ISO date, as of <month/year>);
  • quote blocks: a block with MUST/SHALL in capitals, or more than six prose lines that also cite a record. Reported once per block.

Every comment is checked, public JSDoc, Effect notes, and file headers included: the comment rule keeps those comments but not citations in them. Only the lines a tool reads and code samples are skipped: lint and TypeScript directives (with their reasons), @pr-a11y routing lines, SYNC: blocks, the copyright line, and @example sections and fenced code. A citation that is a file's only link to a record stays in the baseline until a record links the file; the message says how.

no-comment-provenance.baseline.mjs regenerates the list (--check verifies it). README documents the rule.

Baseline counts

2,519 sites in 339 files, on main after the recent comment cleanups.

Package References (ids, PRs/issues, dates) Quote blocks Files
core 1,926 193 272
lab 175 15 25
richtext 118 25 27
native 63 3 14
charts 1 0 1

A claim citation such as spec:AST-108 FR4 counts as two references (the record and the claim).

Risk

Lint only. No source, package, or product behavior changes, no new CI job, and no changeset. Main stays green: every current site is in the baseline. A pull request that adds a new citation in package source fails the existing lint step, as with the other baselined rules. Editing a baselined citation in place (for example FR4 to FR5) also reports it, which is the intent.

Evidence

  • Failure before the change: a new // See #1234 and spec:AST-108. in package source passes lint.
  • Success after the change: the rule tests show it reported; ASTRYX_STRICT_LINT=1 eslint . reports 0 errors on this branch with the baseline.
  • Product/runtime behavior verified unchanged: only eslint.config.js and internal/eslint-plugin-astryx/ change.
  • CI impact: no workflow change. In a full uncached ASTRYX_STRICT_LINT=1 eslint . run (96 s wall on an M-series laptop), the rule takes 0.25–0.5 s, under 0.5% of total rule time (ESLint TIMING=all).

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm exec vitest run internal/eslint-plugin-astryx/no-comment-provenance.test.mjs: 26 cases. Each reported kind (record, claim, reference, date, MUST quote, long citing block); each skip (copyright, @pr-a11y and SYNC: with continuations, directives with reasons, @example in public JSDoc, fenced code, strings, hex colours including upper-case ones, quoted dates, lowercase "must"); citations and quotes in exported JSDoc, Effect notes, and @position header lines are reported; the baseline allows its listed sites; one more site, or a site in another file, is reported.
  • node internal/eslint-plugin-astryx/no-comment-provenance.baseline.mjs --check: up to date.
  • TIMING=all ASTRYX_STRICT_LINT=1 eslint .: 0 errors.

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 2, 2026 10:51am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 2, 2026, 10:59 AM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 2, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The baselined rule matches what the source-comments rule (INV29) and its verification row call for, and the tests and baseline check pass, but one change is needed before this merges. Exported JSDoc and Effect notes are skipped entirely (no-comment-provenance.js lines 421 and 432), so a new #1234, record id or date in them still passes lint, while INV29 bans provenance in every source comment. Please run the finders over those comments too (still skipping @example, fenced code and tool-read lines), regenerate the baseline, and reword the README's "not checked, because they stay". Optional: the long-block quote message names MUST/SHALL when the block has neither, and upper-case hex colours such as #DD1234 match as claim ids.

[Automated review]

Comment on lines +421 to +432
if (isEffectNote(block)) {
return;
}
let quoteIndex = null;
let firstIndex = null;
let lineCount = 0;
let citesRecord = false;
const state = {inToolTag: false, inExample: false, inFence: false};
for (const comment of block) {
if (
DIRECTIVE.test(comment.value.trim()) ||
isPublicJsdoc(comment, exported)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two checks skip an exported declaration's JSDoc and an Effect note entirely, so /** Closes on select, as decided in #9123 (component:Menu FR7). */ on an exported prop passes. INV29 keeps these comments but bans pull request, issue, date and record citations in every source comment. Its verification row counts a new citation with no lint failure as a failure. Please run the finders over these comments too, still skipping @example, fenced code and tool-read lines, and regenerate the baseline.

Comment thread internal/eslint-plugin-astryx/README.md Outdated
Comment on lines +296 to +302
These comments are not checked, because they stay: the copyright line; the file
header lines `@input`, `@output`, `@position`, `@pr-a11y`, and `SYNC:`, with
their continuation lines; lint, TypeScript, and other tool directives (with
their `--` reasons); JSDoc on an exported declaration or a member of one; the
comment before an Effect that names the system it syncs; and code samples
(`@example` sections and fenced code). Adjacent line comments in one column are
one block.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INV29 keeps these comments, but it does not let them keep citations. Once exported JSDoc and Effect notes are checked, this paragraph can list only the lines a tool reads (directives, @pr-a11y, SYNC:) and code samples as unchecked.

'`{{entry}}` is a date stamp. A comment states what is true now; ' +
'version control records when it changed.',
quote:
'`{{entry}}`: this comment quotes requirement text (MUST or SHALL). ' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: a block of more than six lines that cites a record gets this message even when it contains neither MUST nor SHALL. packages/core/src/Chat/useTriggerMenu.tsx:363 is one example. A separate message for the long-block case would match what triggered it.

{
kind: 'claim',
pattern: new RegExp(
`(?<![\\w/-])(?:${CLAIM_PREFIXES.join('|')})-?\\d+[a-z]?\\b`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: # is not in this lookbehind, so upper-case hex colours match as claims (#DD1234 reports DD1234, and #DEC123 reports DEC123). Adding # to the lookbehind avoids that.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · d4c5fc5

⏳ Building… Until it's ready, Storybook · Sandbox open the branch's previous preview.

Current run: Heavy CI deferred: runs when marked ready and before merge. Lint, typecheck and any path-filtered checks ran on this push.


Generated by PR Enrichment workflow | View current CI run

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready to merge: @astryx/no-comment-provenance is the baselined lint the source-comments rule (INV29) asks for, the rule tests and the baseline --check pass, CI lint reports 0 errors, and the baseline still holds against the newer commit on main. Two optional follow-ups: a new site above a baselined one with the same entry takes the file's allowance, so the error lands on the older comment (worth one README sentence), and line comments that start with global, globals or exported are still skipped as directives.

[Automated review]

const QUOTE_BLOCK_LINES = 6;

const DIRECTIVE =
/^(?:eslint\b|eslint-|global\s|globals\s|exported\s|@ts-|\/\s*<reference|prettier-ignore|istanbul\s|c8\s|v8\s|@vitest-environment|@jsx|#__PURE__|@__PURE__|@__NO_SIDE_EFFECTS__|webpack[A-Z]|@refresh|@license|@preserve)/;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: ESLint treats global, globals and exported as directives only in block comments, but this test runs on line comments too. So // global listeners are shared across instances (#4321, spec:AST-108). is skipped whole and passes. Checking those three prefixes only when comment.type === 'Block' closes that gap; no current site depends on it.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready to merge: @astryx/no-comment-provenance is the baselined lint the source-comments rule (INV29) calls for, the rule tests and the baseline --check pass, and CI lint reports 0 errors. Two optional follow-ups:

  • A record cited by path (docs/design/reduced-motion.md in Dialog.tsx, Toast.spec.md in ToastViewport.tsx) is not detected, so a reported spec:AST-108 can be rewritten as a path and pass.
  • A line comment that starts with global, exported or eslint is skipped as a directive, though ESLint reads those only in block comments.

[Automated review]

'g',
),
},
{kind: 'record', pattern: /(?<![\w/#-])AST-\d+[a-z]?(?:\/[A-Z]+-?\d+)?\b/g},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: no finder reads a record cited by path, so // Follows docs/specs/AST-108/spec.md. passes. The prose citations in Dialog.tsx (lines 20 and 24: docs/design/reduced-motion.md, docs/architecture/interaction-modality.md) and ToastViewport.tsx (lines 340 and 414: Toast.spec.md) are neither reported nor baselined. A record-path finder that leaves SYNC: blocks alone (their paths are read by scripts/check-sync.js), or a line under Known limitations, would close the gap.

@cixzhang
cixzhang merged commit 12610cb into main Nov 2, 2026
89 of 92 checks passed
@github-actions
github-actions Bot deleted the lint/no-comment-provenance branch November 3, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — d4c5fc5e Deployed Nov 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant