-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Enum order support #67
Conversation
Wow, first of all, many thanks for your contribution. However, this new behavior is in some way a breaking change - all users will start getting errors in places where they do not expect it. It's a perfectly valid use case to have 2 enum types with the same field set but with different values. To avoid unnecessary surprises I would recommend introducing a feature flag that will enable this extra check. Please examine https://github.com/cezarypiatek/CSharpExtensions/blob/master/src/CSharpExtensions.Analyzers/ReturnValueUnusedAnalyzer.cs as an example of a configurable analyzer. |
src/CSharpExtensions.Analyzers/AddMissingMembersOfTwinTypeCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
@cezarypiatek I've implemented the feature flag. Can you review the code to see if this is what you had in mind. I was unable to use the feature flag json to build correct unit tests, due to cezarypiatek/RoslynTestKit#24 How do you test the analyzer and codefixer with real code? E.g. outside of the unit tests... |
src/CSharpExtensions.Analyzers/AddMissingMembersOfTwinTypeCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
@jerone there are 2 more remarks, I forgot to click "submit review" yesterday 😅 |
Thanks for the collaboration. I merged your changes, the new version should be automatically released any time soon. |
For a project I'm working on, we needed enum order support.
This PR includes tests for enums with constant values and without values (default values).
Because I couldn't find a way to remove members from the enum, I used
WithMembers
to replace all members at once.This forces the correct order and thus keeping the correct default value in sync.
The code fixer will now also append the constant value for enums.
I've included logic to detect if the value was implicit or explicit set.
Keeping it backwards-compatible.
I couldn't test the reporting part, but I extended the message for enums with the value.
Fixes #59 (comment)