feat(modules): add the writing rules of the lint layer and the ingredient-database Quick Fix #298

Merged
abiwab merged 1 commit from feat/modules-lint-rules into dev/1.6 2026-11-26 23:43:10 +01:00
Owner

PR 5b-2 of .notes/backlog/plan-dx-et-aides-ecriture.md (Phase 1 § 1C): new rules of @gram-lang/modules/lint and the ADD_TO_INGREDIENTS_DB Quick Fix.

Lint layer (@gram-lang/modules/lint)

  • LOST_INGREDIENT (warning): lostFrom(compilation, findWrittenIngredients(text)), kept only for tokens inside a mid-step // comment (a section title, a preparation, &@x or @@ are not reported). LintInput.compilation gains registry?. findWrittenIngredients stays backward compatible and now also skips @use directives and a CRLF frontmatter (closed blocks only, old regex as fallback).
  • MERGED_STEP_LINE (info): a [Action] line, a ## … line, or the line after one ending with ->&…, glued under a step. Block comments and the frontmatter are skipped. Preferred fix inserts the blank line, keeping CRLF. (The "line right under ## Section" case from the plan is not flagged: the parser reads it as a step.)
  • SUSPECT_INGREDIENT_NAME (hint): braced names with , ; . (after a 4+ letter word, so St. John's wort is spared) 、 。, more than SUSPECT_NAME_MAX_WORDS = 6 words or SUSPECT_NAME_MAX_GRAPHEMES = 40 graphemes. Non-preferred split fix @A{q}(B).
  • UNREAD_FRONTMATTER (warning): closed block with keys, empty meta; anchored on the first # … or indented line; "Remove this line" only on a # … line. MISSING_TITLE is dropped when the unread block writes title:.
  • ADD_TO_INGREDIENTS_DB: second, never-preferred fix of UNKNOWN_INGREDIENT when LintInput.ingredientsFile: { uri, text } is given. Commented skeleton inserted at the end of the ingredients: block or of the file, escaped name, CRLF and missing final newline handled, no duplicate when the entry is already in the buffer. createFile dropped for now (unreachable: no database, no diagnostic).

Language server

  • ClientProfile.documentChanges; Quick Fixes are written as documentChanges (TextDocumentEdit, version: null) for clients that support them, else changes.
  • The database file (open buffer, else disk) is read only when an UNKNOWN_INGREDIENT asks for its Quick Fixes.

Docs & changeset

  • warnings.mdx (en + fr): one section per new code and the database Quick Fix; modules.mdx (en + fr): LintInput.
  • minor changeset modules-lint-writing-rules.md, complementary to modules-lint.md.

Checks

  • bun test: 4312 pass / 1 skip (baseline 4269 / 1); 43 new tests, none removed or renamed (junit diff); positive tests red without the code.
  • Corpus test: zero diagnostics of the 4 rules on kitchen fixtures, conformance cases, docs examples and docs gram fences (❌/✅ blocks excluded).
  • conformance 148/148 + 24/24 (no golden moved), audit 128 flags (unchanged), playground chunk 1060.9 KB (unchanged), typecheck 24/24, biome clean, deprecations:check no drift, fuzz --iterations 50000 (seed 3248443166): 0 signature.

The isPreferred idempotence invariant in the fuzz is left to PR 6, as agreed; each rule has its own idempotence test here.

PR 5b-2 of `.notes/backlog/plan-dx-et-aides-ecriture.md` (Phase 1 § 1C): new rules of `@gram-lang/modules/lint` and the `ADD_TO_INGREDIENTS_DB` Quick Fix. ## Lint layer (`@gram-lang/modules/lint`) - `LOST_INGREDIENT` (warning): `lostFrom(compilation, findWrittenIngredients(text))`, kept only for tokens inside a mid-step `//` comment (a section title, a preparation, `&@x` or `@@` are not reported). `LintInput.compilation` gains `registry?`. `findWrittenIngredients` stays backward compatible and now also skips `@use` directives and a CRLF frontmatter (closed blocks only, old regex as fallback). - `MERGED_STEP_LINE` (info): a `[Action]` line, a `## …` line, or the line after one ending with `->&…`, glued under a step. Block comments and the frontmatter are skipped. Preferred fix inserts the blank line, keeping CRLF. (The "line right under `## Section`" case from the plan is not flagged: the parser reads it as a step.) - `SUSPECT_INGREDIENT_NAME` (hint): braced names with `, ` `; ` `. ` (after a 4+ letter word, so `St. John's wort` is spared) `、` `。`, more than `SUSPECT_NAME_MAX_WORDS = 6` words or `SUSPECT_NAME_MAX_GRAPHEMES = 40` graphemes. Non-preferred split fix `@A{q}(B)`. - `UNREAD_FRONTMATTER` (warning): closed block with keys, empty `meta`; anchored on the first `# …` or indented line; "Remove this line" only on a `# …` line. `MISSING_TITLE` is dropped when the unread block writes `title:`. - `ADD_TO_INGREDIENTS_DB`: second, never-preferred fix of `UNKNOWN_INGREDIENT` when `LintInput.ingredientsFile: { uri, text }` is given. Commented skeleton inserted at the end of the `ingredients:` block or of the file, escaped name, CRLF and missing final newline handled, no duplicate when the entry is already in the buffer. `createFile` dropped for now (unreachable: no database, no diagnostic). ## Language server - `ClientProfile.documentChanges`; Quick Fixes are written as `documentChanges` (`TextDocumentEdit`, `version: null`) for clients that support them, else `changes`. - The database file (open buffer, else disk) is read only when an `UNKNOWN_INGREDIENT` asks for its Quick Fixes. ## Docs & changeset - `warnings.mdx` (en + fr): one section per new code and the database Quick Fix; `modules.mdx` (en + fr): `LintInput`. - `minor` changeset `modules-lint-writing-rules.md`, complementary to `modules-lint.md`. ## Checks - `bun test`: 4312 pass / 1 skip (baseline 4269 / 1); 43 new tests, none removed or renamed (junit diff); positive tests red without the code. - Corpus test: zero diagnostics of the 4 rules on kitchen fixtures, conformance cases, docs examples and docs `gram` fences (❌/✅ blocks excluded). - conformance 148/148 + 24/24 (no golden moved), audit 128 flags (unchanged), playground chunk 1060.9 KB (unchanged), typecheck 24/24, biome clean, `deprecations:check` no drift, `fuzz --iterations 50000` (seed 3248443166): 0 signature. The `isPreferred` idempotence invariant in the fuzz is left to PR 6, as agreed; each rule has its own idempotence test here.
abiwab merged commit 0eb8eee312 into dev/1.6 2026-11-26 23:43:10 +01:00
abiwab deleted branch feat/modules-lint-rules 2026-11-26 23:43:11 +01:00
Sign in to join this conversation.
No description provided.