feat: Add code fix for INTL0301/INTL0302 (FavorDirectoryEnumerationCalls)#400
Open
BenjaminMichaelis wants to merge 1 commit intomainfrom
Open
feat: Add code fix for INTL0301/INTL0302 (FavorDirectoryEnumerationCalls)#400BenjaminMichaelis wants to merge 1 commit intomainfrom
BenjaminMichaelis wants to merge 1 commit intomainfrom
Conversation
IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs
Fixed
Show fixed
Hide fixed
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/FavorDirectoryEnumerationCalls.cs
Fixed
Show fixed
Hide fixed
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds a code fix provider for the INTL0301 and INTL0302 analyzer rules, which suggest using Directory.EnumerateFiles and Directory.EnumerateDirectories over their GetFiles and GetDirectories counterparts. The code fix automatically replaces these method calls and adds .ToArray() when necessary to maintain type compatibility.
Changes:
- Exposed DiagnosticId constants as public fields in the analyzer for use by the code fix provider
- Implemented a new code fix provider that intelligently replaces method calls and adds ToArray() when the result is assigned to array types
- Added System.Runtime.dll reference to test infrastructure to support System.IO types in tests
- Added comprehensive test cases covering variable assignments and foreach scenarios
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/FavorDirectoryEnumerationCalls.cs | Extracted diagnostic IDs as public constants and fixed trailing whitespace |
| IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/FavorDirectoryEnumerationCalls.cs | New code fix provider that replaces GetFiles/GetDirectories with Enumerate variants and conditionally adds ToArray() |
| IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs | Added System.Runtime.dll metadata reference for test compilation |
| IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs | Added four test cases covering both diagnostic IDs with array assignment and foreach scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/FavorDirectoryEnumerationCalls.cs
Show resolved
Hide resolved
IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs
Show resolved
Hide resolved
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/FavorDirectoryEnumerationCalls.cs
Outdated
Show resolved
Hide resolved
IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs
Show resolved
Hide resolved
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/FavorDirectoryEnumerationCalls.cs
Outdated
Show resolved
Hide resolved
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/FavorDirectoryEnumerationCalls.cs
Show resolved
Hide resolved
IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs
Outdated
Show resolved
Hide resolved
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/FavorDirectoryEnumerationCalls.cs
Outdated
Show resolved
Hide resolved
b51f4f8 to
ab6686b
Compare
…lls) - Add public DiagnosticId301/302 constants to the analyzer (required by the code fix) - Add FavorDirectoryEnumerationCalls CodeFixProvider that renames GetFiles/GetDirectories to their lazy Enumerate* counterparts, wrapping with .ToArray() when the result is assigned to / returned as string[] - Add System.Runtime metadata reference to test helper to support LINQ-based code fixes - Add 4 code fix tests covering both rename and .ToArray() wrapping scenarios Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ab6686b to
34bab89
Compare
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.
No description provided.