Repository navigation
chore(eslint): report provenance in source comments, with a baseline of current sites - #9516
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
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]
| 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) |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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). ' + |
There was a problem hiding this comment.
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`, |
There was a problem hiding this comment.
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.
PR Analysis Report🔎 Preview ·
|
c9c55b3 to
8588b13
Compare
There was a problem hiding this comment.
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)/; |
There was a problem hiding this comment.
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.
… separate long-block message; skip hex colours
8588b13 to
d4c5fc5
Compare
There was a problem hiding this comment.
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.mdinDialog.tsx,Toast.spec.mdinToastViewport.tsx) is not detected, so a reportedspec:AST-108can be rewritten as a path and pass. - A line comment that starts with
global,exportedoreslintis 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}, |
There was a problem hiding this comment.
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.
Maintainer impact
The repository's comment rule (the "Source comments" rule in
docs/architecture/knowledge-contracts.mdand theAGENTS.mdcomment 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 ofpnpm 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-attributeandno-truthy-jsx-guard, and the baseline only shrinks.Change
Adds
@astryx/no-comment-provenanceto the internal ESLint plugin and turns it on forpackages/*/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:
spec:AST-…,component:…,module:…,architecture:…,family:…,design:…,theme:…, bareAST-NNN) and claim ids with a known prefix (FR,INV,DEC,AR,DR, …), using the id grammar thatcheck:knowledgereads;#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;as of <month/year>);MUST/SHALLin 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-a11yrouting lines,SYNC:blocks, the copyright line, and@examplesections 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.mjsregenerates the list (--checkverifies it). README documents the rule.Baseline counts
2,519 sites in 339 files, on main after the recent comment cleanups.
A claim citation such as
spec:AST-108 FR4counts 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
FR4toFR5) also reports it, which is the intent.Evidence
// See #1234 and spec:AST-108.in package source passes lint.ASTRYX_STRICT_LINT=1 eslint .reports 0 errors on this branch with the baseline.eslint.config.jsandinternal/eslint-plugin-astryx/change.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 (ESLintTIMING=all).Scope
Testing
pnpm exec vitest run internal/eslint-plugin-astryx/no-comment-provenance.test.mjs: 26 cases. Each reported kind (record, claim, reference, date,MUSTquote, long citing block); each skip (copyright,@pr-a11yandSYNC:with continuations, directives with reasons,@examplein public JSDoc, fenced code, strings, hex colours including upper-case ones, quoted dates, lowercase "must"); citations and quotes in exported JSDoc, Effect notes, and@positionheader 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.