Code quality rule configuration options

The code quality rules have additional configuration options, besides just configuring their severity. For example, each code quality analyzer can be configured to only apply to specific parts of your codebase. You specify these options by adding key-value pairs to the same EditorConfig file where you specify rule severities and general editor preferences.

Option scopes

Each refining option can be configured for all rules, for a category of rules (for example, Security or Design), or for a specific rule.

All rules

The syntax for configuring an option for all rules is as follows:

Syntax Example
dotnet_code_quality.OptionName = OptionValue dotnet_code_quality.api_surface = public

Category of rules

The syntax for configuring an option for a category of rules (such as Naming, Design, or Performance) is as follows:

Syntax Example
dotnet_code_quality.RuleCategory.OptionName = OptionValue dotnet_code_quality.Naming.api_surface = public

Specific rule

The syntax for configuring an option for a specific rule is as follows:

Syntax Example
dotnet_code_quality.RuleId.OptionName = OptionValue dotnet_code_quality.CA1040.api_surface = public

Options

This section lists some of the available options. To see the full list of available options, see Analyzer configuration.

api_surface

Description Allowable values Default value Configurable rules
Which part of the API surface to analyze public
internal or friend
private
all

Separate multiple values with a comma (,)
public CA1000 CA1003 CA1008 CA1010
CA1012 CA1024 CA1027 CA1028
CA1030 CA1036 CA1040 CA1041
CA1043 CA1044 CA1051 CA1052
CA1054 CA1055 CA1056 CA1058
CA1063 CA1708 CA1710 CA1711
CA1714 CA1715 CA1716 CA1717
CA1720 CA1721 CA1725 CA1801
CA1802 CA1815 CA1819 CA2217
CA2225 CA2226 CA2231 CA2234

exclude_async_void_methods

Description Allowable values Default value Configurable rules
Whether to ignore asynchronous methods that don't return a value true
false
false CA2007

Note

This option was named skip_async_void_methods in an earlier version.

exclude_single_letter_type_parameters

Description Allowable values Default value Configurable rules
Whether to exclude single-character type parameters from the rule, for example, S in Collection<S> true
false
false CA1715

Note

This option was named allow_single_letter_type_parameters in an earlier version.

output_kind

Description Allowable values Default value Configurable rules
Specifies that code in a project that generates this type of assembly should be analyzed One or more fields of the OutputKind enumeration

Separate multiple values with a comma (,)
All output kinds CA2007

required_modifiers

Description Allowable values Default value Configurable rules
Specifies the required modifiers for APIs that should be analyzed One or more values from the below allowed modifiers table

Separate multiple values with a comma (,)
Depends on each rule CA1802
Allowed Modifier Summary
none No modifier requirement
static or Shared Must be declared as static (Shared in Visual Basic)
const Must be declared as const
readonly Must be declared as readonly
abstract Must be declared as abstract
virtual Must be declared as virtual
override Must be declared as override
sealed Must be declared as sealed
extern Must be declared as extern
async Must be declared as async

exclude_extension_method_this_parameter

Description Allowable values Default value Configurable rules
Whether to skip analysis for the this parameter of extension methods true
false
false CA1062

null_check_validation_methods

Description Allowable values Default value Configurable rules
Names of null-check validation methods that validate that arguments passed to the method are non-null Allowed method name formats (separated by |):
- Method name only (includes all methods with the name, regardless of the containing type or namespace)
- Fully qualified names in the symbol's documentation ID format, with an optional M: prefix
None CA1062

additional_string_formatting_methods

Description Allowable values Default value Configurable rules
Names of additional string formatting methods Allowed method name formats (separated by |):
- Method name only (includes all methods with the name, regardless of the containing type or namespace)
- Fully qualified names in the symbol's documentation ID format, with an optional M: prefix
None CA2241

excluded_type_names_with_derived_types

Description Allowable values Default value Configurable rules
Names of types, such that the type and all its derived types are excluded for analysis Allowed symbol name formats (separated by |):
- Type name only (includes all types with the name, regardless of the containing type or namespace)
- Fully qualified names in the symbol's documentation ID format, with an optional T: prefix
None CA1303

excluded_symbol_names

Description Allowable values Default value Configurable rules
Names of symbols that are excluded for analysis Allowed symbol name formats (separated by |):
- Symbol name only (includes all symbols with the name, regardless of the containing type or namespace)
- Fully qualified names in the symbol's documentation ID format. Each symbol name requires a symbol kind prefix, such as M: prefix for methods, T: prefix for types, and N: prefix for namespaces.
- .ctor for constructors and .cctor for static constructors
None CA1062 CA1303 CA2000 CA2100 CA2301 CA2302
CA2311 CA2312 CA2321 CA2322 CA2327 CA2328
CA2329 CA2330 CA3001 CA3002 CA3003 CA3004
CA3005 CA3006 CA3007 CA3008 CA3009 CA3010
CA3011 CA3012 CA5361 CA5376 CA5377 CA5378
CA5380 CA5381 CA5382 CA5383 CA5384 CA5387
CA5388 CA5389 CA5390

disallowed_symbol_names

Description Allowable values Default value Configurable rules
Names of symbols that are disallowed in the context of the analysis Allowed symbol name formats (separated by |):
- Symbol name only (includes all symbols with the name, regardless of the containing type or namespace)
- Fully qualified names in the symbol's documentation ID format. Each symbol name requires a symbol kind prefix, such as M: prefix for methods, T: prefix for types, and N: prefix for namespaces.
- .ctor for constructors and .cctor for static constructors
None CA1031