rspec/rules/S2342/csharp/rule.adoc

50 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
Shared naming conventions allow teams to collaborate efficiently. This rule checks that all ``++enum++`` names match a provided regular expression.
2020-06-30 12:48:07 +02:00
The default configuration is the one recommended by Microsoft:
2020-06-30 12:48:07 +02:00
* Pascal casing, starting with an upper case character, e.g. BackColor
* Short abbreviations of 2 letters can be capitalized, e.g. GetID
* Longer abbreviations need to be lower case, e.g. GetHtml
* If the enum is marked as [Flags] then its name should be plural (e.g. MyOptions), otherwise, names should be singular (e.g. MyOption)
== Noncompliant Code Example
2021-01-27 13:42:22 +01:00
With the default regular expression for non-flags enums: ``++^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$++``
2020-06-30 12:48:07 +02:00
----
public enum foo // Noncompliant
{
FooValue = 0
}
----
2021-01-27 13:42:22 +01:00
With the default regular expression for flags enums: ``++^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$++``
2020-06-30 12:48:07 +02:00
----
[Flags]
public enum Option // Noncompliant
{
None = 0,
Option1 = 1,
Option2 = 2
}
----
== Compliant Solution
----
public enum Foo
{
FooValue = 0
}
----
----
[Flags]
public enum Options
{
None = 0,
Option1 = 1,
Option2 = 2
}
----