feat(tspd): auto-generate linter rule and diagnostic reference pages#11221
Conversation
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
c8f4342 to
31bbb0a
Compare
Add an optional docs field (raw markdown, loaded from a co-located .md file) to linter rule (createRule) and diagnostic (createTypeSpecLibrary) definitions. tspd renders a page per rule (reference/rules/<name>.md) and per diagnostic (reference/diagnostics/<code>.md) plus a diagnostics index, and reports documentation-missing for undocumented rules/diagnostics. Migrates @typespec/http op-reference-container-route and @typespec/openapi3 path-query as pilots. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
31bbb0a to
14d52c9
Compare
|
@timotheeguerin updated the PR to the latest approach (option 2 from your review): diagnostics and linter rules take a |
389c229 to
45b365f
Compare
45b365f to
87bfff5
Compare
…ules Add a referenceDocs.baseUrl field to the library definition. When set, the compiler auto-fills the url of each diagnostic and linter rule that does not specify one explicitly (diagnostics -> <base>/diagnostics/<code>, rules -> <base>/rules/<name>), so the editor and CLI get a documentation link without hardcoding a url per item. Migrate @typespec/http and @typespec/openapi3 to declare referenceDocs and drop the hardcoded rule url. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e server When hovering over a reported error, the language server now renders the extended documentation of the corresponding diagnostic or linter rule (its docs field, inline markdown or a FileRef read lazily) together with a link to the generated reference page when a documentation url is available. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e-diagnostic-docs # Conflicts: # packages/compiler/test/server/get-hover.test.ts
|
Follow-up review fixes (latest in
Added regression coverage for URL generation / explicit-URL preservation and for inline and |
ea625ab to
7758081
Compare
Publish FileRef markdown assets and avoid generating reference links for undocumented diagnostics/rules. On hover, reuse the diagnostics from the last full compile (matched by source location the same way squiggles are) to show the extended documentation of the diagnostic/rule under the cursor, resolved by reusing the library already loaded by the compiler instead of re-resolving and reloading it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: de8537de-5e61-4a0d-b2de-59ec12c15dc4
7758081 to
69c49cd
Compare
…ver into a follow-up PR This PR now only contains the tspd documentation generation (the \docs\ field + \FileRef\, and tspd rendering a page per rule/diagnostic). The \ eferenceDocs.baseUrl\ url auto-generation and the language server hover that surfaces the docs are moved to a separate PR. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: de8537de-5e61-4a0d-b2de-59ec12c15dc4
|
Per discussion with @timotheeguerin, this PR is now scoped to just the |
timotheeguerin
left a comment
There was a problem hiding this comment.
just perf tweak and I think otherwise this looks good
…and document the docs field Address review feedback: read `FileRef` docs with the async `fs/promises` `readFile` instead of `readFileSync`, and document the new `docs` field in the linter authoring guide. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: de8537de-5e61-4a0d-b2de-59ec12c15dc4
57ea64d to
5d447dd
Compare
…t#11320) ## Problem The tspd change that auto-generates one reference page per linter rule (microsoft#11221) moved the `@typespec/http` linter rule page from its historical location: - **Before:** `https://typespec.io/docs/libraries/http/rules/op-reference-container-route` - **After:** `https://typespec.io/docs/libraries/http/reference/rules/op-reference-container-route` This is a breaking change to the public documentation URL. The rule's own `url` field, external links, and the diagnostic "see documentation" link all still point at the historical `libraries/http/rules/<name>` location, which now 404s. ## Fix Use the `--rules-dir ../rules` option (added in microsoft#11316) in http's `regen-docs` script so the per-rule reference pages are written back to `libraries/http/rules/<name>`, restoring the original URL. - `packages/http/package.json` — add `--rules-dir ../rules` to `regen-docs`. - Regenerated docs: the rule page moves back to `libraries/http/rules/op-reference-container-route.md` (100% rename) and `linter.md` links back to `../rules/...`. - `current-sidebar.ts` — re-enable the http "Rules" sidebar group (`hasLinterRules: true`), which autogenerates from `libraries/http/rules`. `@typespec/http` is the only library in this repo that ships linter rules, so no other library is affected. ## Validation - `regen-docs` is stable (running it twice produces no diff). - The restored page URL `libraries/http/rules/op-reference-container-route` matches the rule's hardcoded `url` again. - `chronus verify` passes. Co-authored-by: tadelesh <chenjieshi@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Azure#4968) Bumps the `core` submodule to latest main, which pulls in tspd's per-rule reference page generation (microsoft/typespec#11221). Left as-is, that would orphan Azure's rich hand-written rule pages by emitting barebones pages at a new location. Instead, this migrates each rule to the tspd `docs` field and keeps the generated pages at their existing URLs (net-zero URL change). ## Changes - **core**: bump submodule to latest main — includes the merged tspd `--rules-dir` change (microsoft/typespec#11316) - **86 rules**: add `docs: fileRef.fromPackageRoot("src/rules/<name>.md")`; rich content now lives in `packages/*/src/rules/*.md` - **3 `package.json`** regen-docs scripts: pass `--rules-dir ../rules` so generated pages stay at `libraries/<lib>/rules/<name>` - **astro.config**: 5 redirects for rules whose historical slug differs from the rule name (e.g. `prevent-format` → `no-format`) - **.gitignore**: ignore the generated `libraries/*/rules/` pages (regenerated during `build:web`) - **pnpm-lock**: add `@typespec/events` / `@typespec/sse` workspace links (new `http-specs` peer deps from the bump) - **eng/feeds e2e**: adapt `init-templates.e2e.ts` to the compiler's new `TemplateSource` scaffold API — `ScaffoldingConfig.baseUri` was replaced by `source?: TemplateSource` (microsoft/typespec#11303). Supersedes Azure#4965. - Contributing guide, `create-linter-rule` skill + scaffolder updated to the `docs`-field workflow ## Validation - `typespec-azure-core`, `typespec-azure-resource-manager`, `typespec-client-generator-core` tests pass - `oxlint` clean - `pnpm install --frozen-lockfile` passes - `pnpm regen-docs` clean (no drift) - init-templates e2e: scaffolding tests pass via the new `TemplateSource` path (the 2 `validate` tests that `npm install` an unpublished `@azure-tools/typespec-autorest` version fail only on registry resolution, unrelated to this change) --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Fixes #11141
Auto-generate a reference documentation page per linter rule and per diagnostic with
tspd, so these pages stop being hand-written and drift-prone.Note
This PR is scoped to the
tspddocumentation generation. ThereferenceDocs.baseUrlurl auto-generation and the language server hover that surfaces these docs at a reported error are split into a follow-up PR.Compiler
docsfield on diagnostics and linter rules. BothcreateRuleand diagnostic definitions accept adocsfield for extended documentation:The value is
string | FileRef: either inline markdown, or aFileRefcreated viafileRef.fromPackageRoot("..."). AFileRefis a plain{ kind, path }data object read lazily by tooling, so it is safe to include in code bundled for the browser (e.g. the playground). Because the docs live on the definition, they are available at compile time, not just totspd.tspd
tspd docnow renders:reference/rules/<name>.mdreference/diagnostics/<code>.md(each shows its severity)documentation-missingwarning for every rule/diagnostic withoutdocs.Pilots
Content is faithfully migrated from the hand-written pages, which are then deleted:
@typespec/http— theop-reference-container-routerule.@typespec/openapi3— 6 diagnostics (path-query,duplicate-header,inline-cycle,invalid-schema,invalid-server-variable,union-null); the old hand-writtenemitters/openapi3/diagnostics.mdis replaced by the generated pages underreference/diagnostics/.Validation
compiler,tspd,http,openapi3; regen is stable (running it twice produces no diff).lintgreen for the touched packages; theop-reference-container-routerule tests pass.