S2342 — Enumeration types should comply with a naming convention

Language
VB.NET
Type
Code smell
Severity
Minor
Tags
convention

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:

Noncompliant code example

With the default regular expression for non-flags enums: ^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$


Public Enum foo ' Noncompliant
    FooValue = 0
End Enum

With the default regular expression for flags enums: ^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$


<Flags()>
Public Enum Option ' Noncompliant
    None = 0,
    Option1 = 1,
    Option2 = 2
End Enum

Compliant solution


Public Enum Foo
    FooValue = 0
End Enum

<Flags()>
Public Enum Options
    None = 0,
    Option1 = 1,
    Option2 = 2
End Enum

↑ Back to top