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.
Note
This article does not detail how to configure a rule's severity. The .editorconfig option to set a rule's severity has a different prefix (dotnet_diagnostic
) to the options described here (dotnet_code_quality
). In addition, the options described here pertain to code quality rules only, whereas the severity option applies to code style rules as well. As a quick reference, you can configure a rule's severity using the following option syntax:
dotnet_diagnostic.<rule ID>.severity = <severity value>
However, for detailed information about configuring rule severity, see Severity level.
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 |
The values for <OptionName>
are listed under Options.
Category of rules
The syntax for configuring an option for a category of rules is as follows:
Syntax | Example |
---|---|
dotnet_code_quality.<RuleCategory>.<OptionName> = OptionValue | dotnet_code_quality.Naming.api_surface = public |
The following table lists the available values for <RuleCategory>
.
Design
Documentation
Globalization
Interoperability
Maintainability
Naming
Performance
SingleFile
Reliability
Security
Usage
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
- exclude_async_void_methods
- exclude_single_letter_type_parameters
- output_kind
- required_modifiers
- exclude_extension_method_this_parameter
- null_check_validation_methods
- additional_string_formatting_methods
- excluded_type_names_with_derived_types
- excluded_symbol_names
- disallowed_symbol_names
- exclude_ordefault_methods
- ignore_internalsvisibleto
api_surface
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Which part of the API surface to analyze | public (applies to public and protected APIs)internal or friend (applies to internal and private protected APIs)private (applies to private APIs)all (applies to all APIs)Separate multiple values with a comma (,) |
public |
CA1000 CA1002 CA1003 CA1005 CA1008 CA1010 CA1012 CA1021 CA1024 CA1027 CA1028 CA1030 CA1036 CA1040 CA1041 CA1043 CA1044 CA1045 CA1046 CA1047 CA1051 CA1052 CA1054 CA1055 CA1056 CA1058 CA1062 CA1063 CA1068 CA1070 CA1700 CA1707 CA1708 CA1710 CA1711 CA1714 CA1715 CA1716 CA1717 CA1720 CA1721 CA1725 CA1801 CA1802 CA1815 CA1819 CA1822 CA1859 CA2208 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 | CA1001 CA1054 CA1055 CA1056 CA1062 CA1068 CA1303 CA1304 CA1305 CA1508 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 CA5399 CA5400 |
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 | CA1001 CA1054 CA1055 CA1056 CA1062 CA1068 CA1303 CA1304 CA1305 CA1508 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 CA5399 CA5400 |
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 |
exclude_ordefault_methods
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Excludes FirstOrDefault and LastOrDefault methods from analysis. |
true or false |
false |
CA1826 |
ignore_internalsvisibleto
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Includes assemblies marked with InternalsVisibleToAttribute in analysis. | true or false |
true |
CA1812 CA1852 |
.NET feedback
The .NET documentation is open source. Provide feedback here.
Feedback
Submit and view feedback for