-
-
Notifications
You must be signed in to change notification settings - Fork 63
Add code fixers for MA0182 (Avoid unused internal types) #976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
| // If this is the only type in the file, return a document that deletes the file | ||
| if (allTypes.Count == 1 && allTypes.Contains(typeDeclarationSyntax)) | ||
| { | ||
| // Return an empty document to signal file deletion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot I'm not sure this works. I think you need to use an overload of CodeAction.Create that uses a solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit b59f55d. Changed RemoveTypeDeclaration to return Task<Solution> instead of Task<Document>, and now using SyntaxFactory.CompilationUnit() to create an empty file when removing the only type. All 109 tests passing.
Co-authored-by: meziantou <[email protected]>
| { | ||
| var newRoot = SyntaxFactory.CompilationUnit(); | ||
| var newDocument = document.WithSyntaxRoot(newRoot); | ||
| return newDocument.Project.Solution; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Shouldn't this create a new solution without the document?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit c16d1f0. Now using solution.RemoveDocument(document.Id) to remove the document from the solution when it contains only one unused type. Updated test framework to handle document removal. All 109 tests passing.
Co-authored-by: meziantou <[email protected]>
| var allTypes = GetAllTypeDeclarations(compilationUnit); | ||
|
|
||
| // If this is the only type in the file, remove the document from the solution | ||
| if (allTypes.Count == 1 && allTypes.Contains(typeDeclarationSyntax)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot I think it should also test for assembly attribute [assembly: xyz]. In this case, it shouldn't remove the file. Please add a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit 2e8a1d4. Added check for compilationUnit.AttributeLists.Count == 0 to preserve files with assembly attributes. Added test CodeFix_RemoveType_WithAssemblyAttribute to verify the behavior. All 110 tests passing.
Co-authored-by: meziantou <[email protected]>
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.