Add NEEG004 analyzer to detect ToString() on enums with [EnumExtensions] or EnumExtensions<T> - #196
Merged
Merged
Conversation
Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Create analyzer to detect usages of ToString() and suggest ToStringFast()
Add NEEG004 analyzer to detect ToString() on enums with [EnumExtensions]
Dec 15, 2025
andrewlock
reviewed
Dec 16, 2025
…nt for compatible formats (G, g, empty string) Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
andrewlock
marked this pull request as ready for review
December 17, 2025 19:47
andrewlock
reviewed
Dec 17, 2025
|
|
||
| #pragma warning disable NEEG003 | ||
|
|
||
| [assembly:NetEscapades.EnumGenerators.EnumExtensions<DateTimeKind>()] |
Owner
There was a problem hiding this comment.
@copilot when checking if an enum is valid to be replaced with ToStringFast(), we need to check if it's referenced in an EnumExtensions<T> attribute as well. Add tests and update the implementation
Contributor
Author
There was a problem hiding this comment.
Fixed in commit b291228. The analyzer now checks for EnumExtensions<T> assembly attributes and collects all external enum types during compilation start. Added 8 new tests covering external enum scenarios (DateTimeKind, FileShare) with various format specifiers. All 198 tests pass.
…Extensions<T> attributes Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
Copilot
AI
changed the title
Add NEEG004 analyzer to detect ToString() on enums with [EnumExtensions]
Add NEEG004 analyzer to detect ToString() on enums with [EnumExtensions] or EnumExtensions<T>
Dec 17, 2025
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.
Implements analyzer to detect
ToString()calls on enums decorated with[EnumExtensions]or referenced inEnumExtensions<T>assembly attributes and suggestToStringFast()replacement for better performance.Changes
ToString()calls (with or without format specifiers) on enums with[EnumExtensions]attribute or external enums referenced inEnumExtensions<T>assembly attributes[assembly: EnumExtensions<T>()]attributes (e.g.,DateTimeKind,FileShare)ToString()→ToStringFast()with trivia preservationToStringFast()Example
Analyzer triggers on:
[EnumExtensions]attributeEnumExtensions<T>assembly attributesOriginal prompt
ToString()and suggest replacing withToStringFast()#187💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.