CA1714: Flags enums should have plural names

Value
Rule ID CA1714
Category Naming
Fix is breaking or non-breaking Breaking

Cause

An enumeration has the System.FlagsAttribute and its name does not end in 's'.

By default, this rule only looks at externally visible enumerations, but this is configurable.

Rule description

Types that are marked with FlagsAttribute have names that are plural because the attribute indicates that more than one value can be specified. For example, an enumeration that defines the days of the week might be intended for use in an application where you can specify multiple days. This enumeration should have the FlagsAttribute and could be called 'Days'. A similar enumeration that allows only a single day to be specified would not have the attribute, and could be called 'Day'.

Naming conventions provide a common look for libraries that target the common language runtime. This reduces the learning curve that is required for new software libraries, and increases customer confidence that the library was developed by someone who has expertise in developing managed code.

How to fix violations

Make the name of the enumeration a plural word, or remove the FlagsAttribute attribute if multiple enumeration values should not be specified simultaneously.

When to suppress warnings

It is safe to suppress a violation if the name is a plural word but does not end in 's'. For example, if the multiple-day enumeration that was described previously were named 'DaysOfTheWeek', this would violate the logic of the rule but not its intent. Such violations should be suppressed.

Configure code to analyze

Use the following option to configure which parts of your codebase to run this rule on.

You can configure this option for just this rule, for all rules, or for all rules in this category (Naming). For more information, see Code quality rule configuration options.

Include specific API surfaces

You can configure which parts of your codebase to run this rule on, based on their accessibility. For example, to specify that the rule should run only against the non-public API surface, add the following key-value pair to an .editorconfig file in your project:

dotnet_code_quality.CAXXXX.api_surface = private, internal

See also