feat(modules): add the experimental lint layer and read the editor's diagnostics from it #295

Merged
abiwab merged 3 commits from feat/modules-lint into dev/1.6 2026-11-26 22:46:40 +01:00
Owner

PR 5b-1 of .notes/backlog/plan-dx-et-aides-ecriture.md: the experimental @gram-lang/modules/lint layer, which the language server now reads its diagnostics and Quick Fixes from. gram check will consume the same list in PR 6.

What changes

  • @gram-lang/modules/lint (@experimental):
    • lintDocument(input) returns every diagnostic of a document: its parse error, or else its compile error, the compiler's warnings and the lint layer's rules. Each one comes with its severity, docUrl, deprecated flag, related positions and LintFix[] (FileEdit patches, UTF-16 offsets).
    • allDiagnosticInfo() is the single registry: compiler codes plus PARSE_ERROR, COMPILE_ERROR, MISSING_TITLE, UNUSED_INTERMEDIATE and UNKNOWN_INGREDIENT. docUrlOf(code) gives each code's anchor on the warnings page.
    • parseLintConfig(raw) reads lint.rules (off | hint | info | warning); // gram-ignore CODE silences a code for the next step, or for a section heading's line. Errors are never silenced or lowered.
    • The AST walkers and scanFrontmatter move here from the language server (first commit, no change of behavior).
  • Warning adapter:
    • The adapter moves out of warningToDiagnostic: an import's warning is anchored on its @use line, with related.
    • Every Quick Fix becomes a LintFix, and the regexes on diag.message are gone. MODULE_EXPORT_NOT_FOUND finds its binding by its rank among the missing bindings of the @use line (one warning per missing binding, in the order written). If the counts disagree, no fix is offered.
    • No data is added to Warning, so the compiled JSON and the conformance goldens are unchanged.
  • Language server:
    • diagnostics.ts and code-actions.ts only translate the lint output, and codeDescription.href is set on every diagnostic.
    • Code actions re-lint the fresh state and find the diagnostic back by code and range, so a stale diagnostic gets no fix.
    • lint: is read from .gram/config.yaml.
  • Behavior changes: a syntax error now carries the code PARSE_ERROR. The spelling fix of an unknown ingredient is preferred only when a single name is the closest.
  • Fuzz: new lint-contract invariant (no throw, only registered codes, loc inside the source). Lint time is added to the time budget.
  • Docs (en + fr):
    • warnings.mdx: the table is generated from allDiagnosticInfo(), with each code linked to its anchor. 24 missing sections are added (module codes, DEPRECATED_FRONTMATTER_KEY, lint codes), plus "Configure the lint".
    • Lint section on the modules.mdx API page, and the language server page and README.
    • A test checks that every code has its section in both languages.

Checks

  • bun test: 4261 pass / 1 skip / 0 fail (4215 before); no test lost or renamed (junit comparison).
  • Conformance: 148/148 and 24/24, no golden changed.
  • bun run fuzz --iterations 50000 (seed 461066333): 0 signatures.
  • Audit: 128 flags (unchanged).
  • Playground chunk: 1060.9 KB (unchanged, forced build); the lint layer is not in the client bundle.
  • typecheck, biome (error level), deprecations:check: OK.

Next

5b-2: LOST_INGREDIENT, MERGED_STEP_LINE, SUSPECT_INGREDIENT_NAME, UNREAD_FRONTMATTER and the ADD_TO_INGREDIENTS_DB Quick Fix.

PR 5b-1 of `.notes/backlog/plan-dx-et-aides-ecriture.md`: the experimental `@gram-lang/modules/lint` layer, which the language server now reads its diagnostics and Quick Fixes from. `gram check` will consume the same list in PR 6. ## What changes - **`@gram-lang/modules/lint`** (`@experimental`): - `lintDocument(input)` returns every diagnostic of a document: its parse error, or else its compile error, the compiler's warnings and the lint layer's rules. Each one comes with its severity, `docUrl`, `deprecated` flag, `related` positions and `LintFix[]` (`FileEdit` patches, UTF-16 offsets). - `allDiagnosticInfo()` is the single registry: compiler codes plus `PARSE_ERROR`, `COMPILE_ERROR`, `MISSING_TITLE`, `UNUSED_INTERMEDIATE` and `UNKNOWN_INGREDIENT`. `docUrlOf(code)` gives each code's anchor on the warnings page. - `parseLintConfig(raw)` reads `lint.rules` (`off` | `hint` | `info` | `warning`); `// gram-ignore CODE` silences a code for the next step, or for a section heading's line. Errors are never silenced or lowered. - The AST walkers and `scanFrontmatter` move here from the language server (first commit, no change of behavior). - **Warning adapter**: - The adapter moves out of `warningToDiagnostic`: an import's warning is anchored on its `@use` line, with `related`. - Every Quick Fix becomes a `LintFix`, and the regexes on `diag.message` are gone. `MODULE_EXPORT_NOT_FOUND` finds its binding by its rank among the missing bindings of the `@use` line (one warning per missing binding, in the order written). If the counts disagree, no fix is offered. - No `data` is added to `Warning`, so the compiled JSON and the conformance goldens are unchanged. - **Language server**: - `diagnostics.ts` and `code-actions.ts` only translate the lint output, and `codeDescription.href` is set on every diagnostic. - Code actions re-lint the fresh state and find the diagnostic back by code and range, so a stale diagnostic gets no fix. - `lint:` is read from `.gram/config.yaml`. - **Behavior changes**: a syntax error now carries the code `PARSE_ERROR`. The spelling fix of an unknown ingredient is preferred only when a single name is the closest. - **Fuzz**: new `lint-contract` invariant (no throw, only registered codes, loc inside the source). Lint time is added to the time budget. - **Docs (en + fr)**: - `warnings.mdx`: the table is generated from `allDiagnosticInfo()`, with each code linked to its anchor. 24 missing sections are added (module codes, `DEPRECATED_FRONTMATTER_KEY`, lint codes), plus "Configure the lint". - `Lint` section on the `modules.mdx` API page, and the language server page and README. - A test checks that every code has its section in both languages. ## Checks - `bun test`: 4261 pass / 1 skip / 0 fail (4215 before); no test lost or renamed (junit comparison). - Conformance: 148/148 and 24/24, no golden changed. - `bun run fuzz --iterations 50000` (seed 461066333): 0 signatures. - Audit: 128 flags (unchanged). - Playground chunk: 1060.9 KB (unchanged, forced build); the lint layer is not in the client bundle. - `typecheck`, biome (error level), `deprecations:check`: OK. ## Next 5b-2: `LOST_INGREDIENT`, `MERGED_STEP_LINE`, `SUSPECT_INGREDIENT_NAME`, `UNREAD_FRONTMATTER` and the `ADD_TO_INGREDIENTS_DB` Quick Fix.
abiwab merged commit f79a3ac4a0 into dev/1.6 2026-11-26 22:46:40 +01:00
abiwab deleted branch feat/modules-lint 2026-11-26 22:46:41 +01:00
Sign in to join this conversation.
No description provided.