dotnet / dotnet/roslynator

Suggestion: [Flags] enumeration analyzer

Open
#431 3 comments 0 reactions 0 assignees View on GitHub
Area-Analyzers Feature Request
Dominant language
C#
Stars
3.5k
Forks
294
Avg merge
2h 30m
Merged PRs (30d)
4

Description

Imagine an enumeration:

``` csharp
[Flags]
public enum FlagsEnumeration
{
Flag1 = 1,
Flag2 = 2,
Flag3 = 4,
Flag4 = 8
}
```

Now imagine we have modified the enum:

``` csharp
[Flags]
public enum FlagsEnumeration
{
Flag1 = 1,
Flag2 = 2,
Flag3 = 4,
Flag4 = 8,
Flag5 = 10,
Flag6
}
```

**The situation with `Flag5`** is a bit tricky. There are two situations I can think of:
1. The `Flag5` member is a new member of enumeration and his value was set accidentally.
_QuickFix: can suggest to change the value to 16_
2. The `Flag5` member is multiple flags member i.e. `Flag5` is logically `Flag4` + `Flag2`.
_QuickFix: can suggest to change the value to `Flag4 | Flag2`._

**The situation with `Flag6`** is more straight forward and could be reported somehow like: `Flags enumeration member doen't have explicit value set.`.

Contributor guide

Open the contributing guide

Research direction

Start with the C# enum examples and the two proposed Flag5 cases in the issue, then review the repository's existing analyzer and code-fix entry points. Done should include a Flags-enumeration diagnostic for members without explicit values and a resolved design for the suggested value and bitwise-combination fixes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.