feat(linter): add no-unused-types rule to warn on unused type declarations#20035
Open
myaschmitz wants to merge 6 commits into
Open
feat(linter): add no-unused-types rule to warn on unused type declarations#20035myaschmitz wants to merge 6 commits into
myaschmitz wants to merge 6 commits into
Conversation
…tions Adds a new linter rule `no-unused-types` that emits a warning when a user-defined type is declared but never referenced, mirroring the existing `no-unused-vars` and `no-unused-params` rules. Types marked with @export() are excluded. Includes a `Remove unused type` quick-fix, resource strings, bicepconfig schema entry, and unit tests. Fixes #11876 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
Test this change out locally with the following install scripts (Action run 29538039388) VSCode
Azure CLI
|
…types - Regenerate 5 diagnostics baselines to include new no-unused-types warnings - Disable no-unused-types in TypeStringifierTests.Compile since those tests compile standalone, intentionally-unused type declarations Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Exclude linter diagnostics from error-only/no-diagnostic assertions and add the expected no-unused-types warnings to tests that assert linter output. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
myaschmitz
marked this pull request as ready for review
July 14, 2026 21:45
| { | ||
| CompileAndTest(text, new(OnCompileErrors.Ignore), unusedTypes); | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Could you also add a test to verify the code fix works?
See
for an example of how to do this.Adds two code-fix tests for the no-unused-types rule: one verifying the quick fix removes a lone unused type, and one verifying it removes only the unused type while leaving referenced types intact. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Explain why exported types are skipped (external references aren't visible to single-file analysis) and why a self-binding declaration counts as unused. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
anthony-c-martin
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new linter rule
no-unused-typesthat emits a warning when a user-defined type is declared but never referenced, mirroring the existingno-unused-varsandno-unused-paramsrules. Types marked with@export()are excluded, and aRemove unused typequick-fix is provided.Fixes #11876
Example Usage
Given the following Bicep file:
The linter reports:
The rule defaults to
warninglevel and can be configured inbicepconfig.json.Changes
Checklist
Microsoft Reviewers: Open in CodeFlow