feat(cli): run gram check on the shared lint layer and add --format json #299

Merged
abiwab merged 1 commit from feat/check-lint-json into dev/1.6 2026-11-27 13:28:55 +01:00
Owner

PR 6a of .notes/backlog/plan-dx-et-aides-ecriture.md (phase 1 § 1C, "CLI gram check"). --fix and the fuzz idempotence invariant follow in PR 6b.

What changes

  • gram check runs lintDocument (@gram-lang/modules/lint) on each file, prepared as the language server prepares it: its own AST, the composed and analyzed compilation, the @use graph, the database, and the lint: settings of the file's own project. The terminal and JSON outputs come from the same list.
    • The home-made Database diagnostic is replaced by UNKNOWN_INGREDIENT on each mention, with the closest name.
    • A cause in a dependency is printed as ↳ see base.gram:3:5.
    • The codes the editor hides (MISSING_MACROS, UNKNOWN_MASS, MISSING_INGREDIENT) are listed.
  • New --format json option: { version: 1, files, diagnostics } on stdout, nothing else on stdout.
    • Each diagnostic has the LintDiagnostic fields, plus file, line, col, endLine and endCol (from 1, UTF-16 columns). Uris are file:// URLs.
    • The schema is pinned by a snapshot.
    • --format is validated. When no file matches, the empty report is still printed, with exit code 1.
  • --strict keeps its meaning: every warning and info becomes an error, never a hint. --skip-db keeps the database out.
  • modules/lint changes:
    • UNKNOWN_INGREDIENT now carries data.name.
    • MISSING_INGREDIENT is left out for an ingredient the file already flags. It is matched on its message, rendered from kitchen's template, so the compiled JSON and the goldens do not move.
    • buildLineIndex and offsetToPosition are shared with the LSP.
  • Docs in en + fr:
    • cli.mdx: full version: 1 schema and a CI example.
    • ai-generation-notes.mdx: the "generate, check, correct" loop.
    • warnings.mdx: the "Configure the lint" sentence now names gram check.
  • Changeset: minor, cli and modules. It warns that a strict CI run may now fail on the new checks.

Checks

  • bun test: 4322 pass, 1 skip, 0 fail (was 4312 pass, 1 skip).
  • Conformance: 148/148 and 24/24, no golden changed.
  • Fuzz: 50,000 inputs, 0 signatures.
  • Audit: 128, unchanged.
  • Playground chunk: 1060.9 KB, unchanged.
  • Typecheck, biome and deprecations:check pass.
  • The new tests fail without the change.
  • One test renamed on purpose, because the level changed: "reports a missing ingredient as a "warning" by default" is now "… as an "info", on its mention, by default".
  • LSP ↔ CLI parity test: the real dist/server.cjs and the real CLI run on one file with @use, database: and lint.rules, and give the same codes, severities and positions.
PR 6a of `.notes/backlog/plan-dx-et-aides-ecriture.md` (phase 1 § 1C, "CLI `gram check`"). `--fix` and the fuzz idempotence invariant follow in PR 6b. ## What changes - `gram check` runs `lintDocument` (`@gram-lang/modules/lint`) on each file, prepared as the language server prepares it: its own AST, the composed and analyzed compilation, the `@use` graph, the database, and the `lint:` settings of the file's own project. The terminal and JSON outputs come from the same list. - The home-made `Database` diagnostic is replaced by `UNKNOWN_INGREDIENT` on each mention, with the closest name. - A cause in a dependency is printed as `↳ see base.gram:3:5`. - The codes the editor hides (`MISSING_MACROS`, `UNKNOWN_MASS`, `MISSING_INGREDIENT`) are listed. - New `--format json` option: `{ version: 1, files, diagnostics }` on stdout, nothing else on stdout. - Each diagnostic has the `LintDiagnostic` fields, plus `file`, `line`, `col`, `endLine` and `endCol` (from 1, UTF-16 columns). Uris are `file://` URLs. - The schema is pinned by a snapshot. - `--format` is validated. When no file matches, the empty report is still printed, with exit code 1. - `--strict` keeps its meaning: every warning and info becomes an error, never a `hint`. `--skip-db` keeps the database out. - `modules/lint` changes: - `UNKNOWN_INGREDIENT` now carries `data.name`. - `MISSING_INGREDIENT` is left out for an ingredient the file already flags. It is matched on its message, rendered from kitchen's template, so the compiled JSON and the goldens do not move. - `buildLineIndex` and `offsetToPosition` are shared with the LSP. - Docs in en + fr: - `cli.mdx`: full `version: 1` schema and a CI example. - `ai-generation-notes.mdx`: the "generate, check, correct" loop. - `warnings.mdx`: the "Configure the lint" sentence now names `gram check`. - Changeset: `minor`, `cli` and `modules`. It warns that a strict CI run may now fail on the new checks. ## Checks - `bun test`: 4322 pass, 1 skip, 0 fail (was 4312 pass, 1 skip). - Conformance: 148/148 and 24/24, no golden changed. - Fuzz: 50,000 inputs, 0 signatures. - Audit: 128, unchanged. - Playground chunk: 1060.9 KB, unchanged. - Typecheck, biome and `deprecations:check` pass. - The new tests fail without the change. - One test renamed on purpose, because the level changed: "reports a missing ingredient as a "warning" by default" is now "… as an "info", on its mention, by default". - LSP ↔ CLI parity test: the real `dist/server.cjs` and the real CLI run on one file with `@use`, `database:` and `lint.rules`, and give the same codes, severities and positions.
feat(cli): run gram check on the shared lint layer and add --format json
All checks were successful
CI / Build & Test (pull_request) Successful in 6m38s
5742d55bca
abiwab merged commit e4f40d8853 into dev/1.6 2026-11-27 13:28:55 +01:00
abiwab deleted branch feat/check-lint-json 2026-11-27 13:28:55 +01:00
Sign in to join this conversation.
No description provided.