-
Notifications
You must be signed in to change notification settings - Fork 464
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
CA1700: Do not name enum values 'Reserved' #3365
Conversation
<value>This rule assumes that an enumeration member that has a name that contains "reserved" is not currently used but is a placeholder to be renamed or removed in a future version. Renaming or removing a member is a breaking change.</value> | ||
</data> | ||
<data name="DoNotNameEnumValuesReservedMessage" xml:space="preserve"> | ||
<value>If '{0}.{1}' is not used in the current implementation, remove it. Otherwise give it a meaningful name.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message is copied from legacy fxcop
@@ -1370,4 +1370,13 @@ | |||
<data name="EnumShouldNotHaveDuplicatedValuesTitle" xml:space="preserve"> | |||
<value>Enums values should not be duplicated</value> | |||
</data> | |||
<data name="DoNotNameEnumValuesReservedDescription" xml:space="preserve"> | |||
<value>This rule assumes that an enumeration member that has a name that contains "reserved" is not currently used but is a placeholder to be renamed or removed in a future version. Renaming or removing a member is a breaking change.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from first part of the rule description.
Codecov Report
@@ Coverage Diff @@
## master #3365 +/- ##
========================================
Coverage 95.30% 95.30%
========================================
Files 1025 1027 +2
Lines 232931 233052 +121
Branches 15052 15068 +16
========================================
+ Hits 221990 222107 +117
- Misses 9278 9282 +4
Partials 1663 1663 |
s_localizableTitle, | ||
s_localizableMessageRule, | ||
DiagnosticCategory.Naming, | ||
RuleLevel.IdeHidden_BulkConfigurable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What shall be the default level?
FYI: You will need to fix a new RS diagnostic once #3444 goes in. |
{ | ||
var field = (IFieldSymbol)context.Symbol; | ||
|
||
// FxCop compat: only analyze externally visible symbols by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for handling this!
} | ||
|
||
|
||
if (field.ContainingType?.TypeKind == TypeKind.Enum && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Might be cheaper to do this checks before the MatchesConfiguredVisibility
check...
|
||
|
||
if (field.ContainingType?.TypeKind == TypeKind.Enum && | ||
field.Name.Contains("Reserved")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FxCop rule implementation uses WordParser
, which has been ported to this repo, so we should also match it:
if (!WordParser.ContainsWord(member.Name.Name, WordParserOptions.SplitCompoundWords, "reserved"))
return null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can likely write a test by using a field name such as Preserved
or such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM - should be good to merge once the suggestions are addressed. Thanks!
} | ||
|
||
// FxCop compat: only analyze externally visible symbols by default. | ||
if (!field.MatchesConfiguredVisibility(context.Options, Rule, context.CancellationToken)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the analyzer configuration document that this rule supports api_surface
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good to merge once the analyzer configuration document is updated. Thanks!
Fix #440