Add documentation rules to the library linter - #11543
Conversation
72c972c to
7f1f47f
Compare
8aaaa6b to
de6380d
Compare
There was a problem hiding this comment.
Pull request overview
Adds documentation validation to @typespec/library-linter so libraries can’t publish undocumented public API surface or doc comments that reference non-existent members/tags, with diagnostics reported on the relevant declarations for accurate editor squiggles.
Changes:
- Add
missing-documentationandextraneous-documentationdiagnostics to the library-linter ruleset and wire them into$onValidate. - Implement documentation analysis over public library declarations/members, including handling of decorator docs and template-related traversal.
- Add/adjust tests and documentation (README + Chronus entry) to cover and describe the new rules.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/library-linter/src/validate-docs.ts | Implements the new documentation validation logic and diagnostic reporting. |
| packages/library-linter/src/linter.ts | Hooks documentation validation into the library-linter validate pass. |
| packages/library-linter/src/lib.ts | Registers the new diagnostic codes and message templates. |
| packages/library-linter/test/validate-docs.test.ts | Adds unit tests covering missing/extraneous documentation scenarios. |
| packages/library-linter/test/linter.test.ts | Updates existing tests to include docs so they don’t fail under the new rules. |
| packages/library-linter/README.md | Documents the new linter rules and their intent. |
| .chronus/changes/library-linter-doc-validation-2026-8-11.md | Adds changelog entry for the new rules. |
| if (typeof member.name !== "string") return; | ||
| if (!container?.name) return; | ||
| if (documentedByTag.has(member.name)) return; | ||
| if (!isPublicLibraryType(program, container)) return; | ||
| if (!isPublicLibraryType(program, member)) return; | ||
| if (getDocumentation(program, member)) return; | ||
|
|
||
| report(program, { | ||
| code: "missing-documentation", | ||
| messageId: "member", | ||
| format: { kind, name: member.name, container: container.name ?? "" }, | ||
| target: member, | ||
| }); | ||
| } |
de6380d to
933cd3f
Compare
|
Good catch — fixed in 933cd3f.
This surfaced a real bug in Added three regression tests (unknown tag on a property, |
commit: |
|
All changed packages have been documented.
Show changes
|
…ntation rules Adds two rules to the library linter: - `missing-documentation` warns when a public declaration or member of the library has no doc comment or `@doc`. - `extraneous-documentation` warns when a doc comment documents something that does not exist: an unresolved `@param`/`@prop`/`@template`, a `@returns`/`@errors` on a type that cannot have one, or an unknown tag (usually an unescaped code reference). Fixes #1229 Fixes #2090
933cd3f to
65515f2
Compare
Nothing today stops a library from publishing an undocumented declaration — the only signal is
tspd'sdocumentation-missing, which runs duringregen-docs, reports with no file or line, and is not build-breaking. Nothing at all catches a doc comment that documents something that does not exist.Two rules in
@typespec/library-linter, reported against the offending declaration so the squiggle lands in the right place:missing-documentation— a public declaration or member has no doc comment and no@doc. Covers models, enums, unions, scalars, interfaces, operations and decorators, plus their members: properties, enum members, union variants, operation and decorator parameters, and template parameters.@param/@propon the container counts as documenting the member. Anything in aPrivatenamespace or markedinternalis skipped.extraneous-documentation— a doc comment documents something that is not there:That last one is the common case and it is not cosmetic: the parser treats everything after the bogus tag as tag content, so the description is silently truncated on the published page. This is how protobuf ended up shipping a bullet that reads
- not fall within any range that was [marked reserved](#.Merge last
lint-typespec-libraryalready runs with--warn-as-errorin every library'sbuild, so these rules are enforced the moment this merges. CI on this PR stays red until all four documentation PRs land, which fix the 97 real violations these rules found:httpjson-schemarestprotobuf,graphql,events,http-clientThose four are independent of each other and of this PR, and can merge in any order. This one goes last.
Fixes #1229
Fixes #2090