You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SA1402: Remove unused usings from extracted files - #4307
The SA1402 code fix copied every using directive into a new file, including directives only needed by the type that remained in the original file. It now removes compiler-identified unnecessary imports from each extracted document, independently for linked project copies, while retaining required imports and formatting.
The regression test failed before the product change because Bar.cs incorrectly contained using System.Collections.Generic;. The complete SA1402 suite passes on the C# 6 and C# 15 test projects (65 and 124 tests respectively). The analyzer is unchanged, so there is no analyzer performance impact. One existing expected output was updated because the extracted type no longer needs using System;.
❌ Patch coverage is 94.59877% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.62%. Comparing base (3410bc0) to head (eb7f4ce).
Honor cancellation when pruning unused imports and preserve spacing around namespace imports and file headers.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Normalize namespace trivia by syntax identity and retain comments and conditional directives around extracted types.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Normalize only the separator following the full file header and retain all subsequent directives and comments.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
CS8019 only accounts for active code. If the extracted class uses List<int> solely inside an inactive #if FEATURE block, its ordinary using System.Collections.Generic; is removed: the existing directive guards only inspect the using itself. The extracted file then fails to compile when FEATURE is enabled. Conservatively retain imports when the extracted tree contains disabled text, and add a regression covering both symbol configurations.
Skip using directives containing directives and distinguish the file header from following import comments.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
An unused import such as using /* Important comment */ System; passes this guard, but KeepExteriorTrivia at line 314 discards the comment between its tokens. Preserve interior comments or leave these imports intact. Add a regression verifying that an internally commented unused import survives extraction.
Normalize separators after commented namespace imports
The separator cleanup misses comments on namespace-scoped imports. With // Import comment before two unused usings inside a namespace, KeepExteriorTrivia transfers the comment and the imports' line endings to the extracted class. Both trimming passes stop at the comment, and this header-only cleanup skips the namespace, leaving consecutive blank lines that trigger SA1507. Normalize removal-created separators after preserved namespace import comments too, without changing declaration comments or directives, and add a fixed-output regression.
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
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.
Fixes #3109
The SA1402 code fix copied every
usingdirective into a new file, including directives only needed by the type that remained in the original file. It now removes compiler-identified unnecessary imports from each extracted document, independently for linked project copies, while retaining required imports and formatting.The regression test failed before the product change because
Bar.csincorrectly containedusing System.Collections.Generic;. The complete SA1402 suite passes on the C# 6 and C# 15 test projects (65 and 124 tests respectively). The analyzer is unchanged, so there is no analyzer performance impact. One existing expected output was updated because the extracted type no longer needsusing System;.