Create Roslyn analyzer for converting runtime `Enum.ToString()` calls to `nameof(Enum)`
- Dominant language
- C#
- Stars
- 2.4k
- Forks
- 658
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 9
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Task description
When looking through the codebase, I noticed a few places where we are doing:
```c#
field.PutAttribute(legacyKey, LegacyDocValuesType.BYTES_FIXED_DEREF.ToString());
```
The `BYTES_FIXED_DEREF` is a compile-time enum value, so it would both be more readable, and save an initial allocation if we changed it to:
```c#
field.PutAttribute(legacyKey, nameof(LegacyDocValuesType.BYTES_FIXED_DEREF));
```
I had ChatGPT sketch up the code for what this analyzer and code fix would look like:
https://chatgpt.com/share/69f41082-6ccc-8323-8639-9d4b6ff906f3
Note that this won't work on runtime values of variables that are declared `LegacyDocValuesType`, it is only sensible to do this when referencing the enum value directly as in the above example.
Contributor guide
Research direction
Start by reviewing the linked Roslyn analyzer and code-fix sketch, then locate the project's analyzer entry points and test coverage. Validate the direct enum-member example, while ensuring runtime enum variables are excluded; done means the analyzer offers the conversion and its tests cover the expected diagnostic and fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100