Skip to content

feat(compiler): expose suppression inspection APIs - #12095

Open
Timothee Guerin (timotheeguerin) wants to merge 4 commits into
microsoft:mainfrom
timotheeguerin:feat/suppression-inspection
Open

Timothee Guerin (timotheeguerin) wants to merge 4 commits into
microsoft:mainfrom
timotheeguerin:feat/suppression-inspection

Conversation

@timotheeguerin

@timotheeguerin Timothee Guerin (timotheeguerin) commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Suppression reporting tools currently reimplement directive parsing, declaration-context traversal, and YAML extraction to inspect files without compiling a project. Expose this information directly from the compiler, and let tools inspecting compiled programs read observed usage from the existing tracker.

import { collectLinterDisables } from "@typespec/compiler";
import { collectSuppressions, getSuppressions, parse } from "@typespec/compiler/ast";

const suppressions = collectSuppressions(parse(source));
const [disables, diagnostics] = collectLinterDisables(configText);
const observed = getSuppressions(program); // Each result includes `used`.

Inline results include the directive, attached node, source location, and structured declaration context. Compiled results reuse the internal tracker and snapshot whether each project suppression has matched a diagnostic so far, including rejected attempts to suppress errors. used: false does not establish that a suppression is unnecessary under other settings: a rule may be disabled, a source unavailable, an emitter skipped, or compilation stopped early. These limits are documented in the API comments.

Config results include local rule disables, justifications, key locations, and diagnostics. Parse-only APIs preserve written rule codes without loading libraries or following inherited configuration; reporting identities remain consumer-defined.

Addresses the compiler-side work for Azure/typespec-azure#5030. Consumer showcase: Azure/azure-rest-api-specs#46983.

@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates labels Oct 2, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@12095

commit: c849b28

@azure-sdk-automation

azure-sdk-automation Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/compiler
Show changes

@typespec/compiler - feature ✏️

Inspect inline suppressions and local linter disables without compiling a project. Inline results include declaration context and source locations; config results include rule-key locations and diagnostics. For compiled programs, inspect whether each project suppression matched a diagnostic using getSuppressions.,> ,> ts,> import { collectLinterDisables } from "@typespec/compiler";,> import { collectSuppressions, getSuppressions, parse } from "@typespec/compiler/ast";,> ,> const script = parse(source);,> const suppressions = collectSuppressions(script);,> const [disables, diagnostics] = collectLinterDisables(configText);,> const observedSuppressions = getSuppressions(program); // Includes a `used` flag.,> ,> ,> Usage is a snapshot of diagnostics matched so far in that compilation, including rejected attempts to suppress errors. An unmatched suppression may be needed under other settings: its rule could be disabled, its diagnostic source unavailable, its emitter skipped, or compilation could stop before the relevant stage runs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 Medium severity · 3 Low severity

Open (4)
What changed in this PR

Expose compiler APIs that let tools inspect inline #suppress directives and config-based linter.disable entries without compiling a full project.

Changes:

  • Added collectSuppressions() (AST-level) with source locations and declaration-context scope, exported via @typespec/compiler/ast.
  • Added collectLinterDisables() (config YAML-level) with key locations + diagnostics, exported from @typespec/compiler.
  • Refactored suppression tracking to reuse the AST collector; added tests and changelog entry.
File Description
website/​src/​content/​docs/​docs/​language-basics/​directives.md Removes outdated statement about lack of an API for suppressions.
packages/​compiler/​src/​ast/​suppressions.ts Introduces AST suppression collection with scope + location.
packages/​compiler/​src/​ast/​index.ts Exports new suppression inspection API/types.
packages/​compiler/​src/​config/​linter-disables.ts Adds YAML config linter.disable extraction with locations + diagnostics.
packages/​compiler/​src/​yaml/​parser.ts Adds parseYamlDocument() to expose raw YAML document for inspection use-cases.
packages/​compiler/​src/​core/​directives.ts Centralizes directive parsing for reuse.
packages/​compiler/​src/​core/​suppression-tracking.ts Reuses collectSuppressions() for project suppression tracking.
packages/​compiler/​src/​index.ts Exports collectLinterDisables as a public compiler API.
packages/​compiler/​test/​ast/​suppressions.test.ts Adds coverage for new AST suppression collector behavior.
packages/​compiler/​test/​config/​linter-disables.test.ts Adds coverage for linter disable extraction, locations, and diagnostics.
.chronus/​changes/​compiler-suppression-inspection.md Adds changelog entry + usage snippet.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread website/src/content/docs/docs/language-basics/directives.md
Comment thread packages/compiler/src/ast/suppressions.ts
Comment thread packages/compiler/src/ast/suppressions.ts
Comment thread packages/compiler/src/yaml/parser.ts
Copilot AI balanced review requested due to automatic review settings October 6, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants