
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
88 lines
1.6 KiB
Plaintext
88 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Shared naming conventions allow teams to collaborate efficiently. This rule checks that all ``++enum++`` names match a provided regular expression.
|
|
|
|
|
|
The default configuration is the one recommended by Microsoft:
|
|
|
|
* 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
|
|
|
|
With the default regular expression for non-flags enums: ``++^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$++``
|
|
|
|
[source,csharp]
|
|
----
|
|
public enum foo // Noncompliant
|
|
{
|
|
FooValue = 0
|
|
}
|
|
----
|
|
With the default regular expression for flags enums: ``++^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$++``
|
|
|
|
[source,csharp]
|
|
----
|
|
[Flags]
|
|
public enum Option // Noncompliant
|
|
{
|
|
None = 0,
|
|
Option1 = 1,
|
|
Option2 = 2
|
|
}
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
public enum Foo
|
|
{
|
|
FooValue = 0
|
|
}
|
|
----
|
|
|
|
[source,csharp]
|
|
----
|
|
[Flags]
|
|
public enum Options
|
|
{
|
|
None = 0,
|
|
Option1 = 1,
|
|
Option2 = 2
|
|
}
|
|
----
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
=== Parameters
|
|
|
|
.format
|
|
****
|
|
|
|
----
|
|
^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$
|
|
----
|
|
|
|
Regular expression used to check the enumeration type names against
|
|
****
|
|
.flagsAttributeFormat
|
|
****
|
|
|
|
----
|
|
^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$
|
|
----
|
|
|
|
Regular expression used to check FlagsAttribute enumeration type names against
|
|
****
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|