Skip to content

Comments

feat: Add code fix for INTL0301/INTL0302 (FavorDirectoryEnumerationCalls)#400

Open
BenjaminMichaelis wants to merge 1 commit intomainfrom
bmichaelis/codefixFavorDirectoryEnumerationCalls
Open

feat: Add code fix for INTL0301/INTL0302 (FavorDirectoryEnumerationCalls)#400
BenjaminMichaelis wants to merge 1 commit intomainfrom
bmichaelis/codefixFavorDirectoryEnumerationCalls

Conversation

@BenjaminMichaelis
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings February 24, 2026 08:34
@BenjaminMichaelis BenjaminMichaelis self-assigned this Feb 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@BenjaminMichaelis BenjaminMichaelis force-pushed the bmichaelis/codefixFavorDirectoryEnumerationCalls branch from b51f4f8 to ab6686b Compare February 24, 2026 08:43
…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>
@BenjaminMichaelis BenjaminMichaelis force-pushed the bmichaelis/codefixFavorDirectoryEnumerationCalls branch from ab6686b to 34bab89 Compare February 24, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant