Training
Learning path
Implement finance and operations apps - Training
Plan and design your project methodology to successfully implement finance and operations apps with FastTrack services, data management and more.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
Each refining option can be configured for all rules, for a category of rules (for example, Security or Design), or for a specific rule.
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.
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
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 |
This section lists some of the available options. To see the full list of available options, see Analyzer configuration.
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 |
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.
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.
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 |
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 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Whether to skip analysis for the this parameter of extension methods |
true false |
false |
CA1062 |
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 |
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 |
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 |
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 |
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 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Excludes FirstOrDefault and LastOrDefault methods from analysis. |
true or false |
false |
CA1826 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Includes assemblies marked with InternalsVisibleToAttribute in analysis. | true or false |
true |
CA1812 CA1852 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Boolean option to enable heuristic detection of additional string formatting methods. A method is considered a string formatting method if it has a string format parameter followed by a params object[] parameter. |
true or false |
false |
CA2241 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Configure which value of DllImportSearchPath is unsafe for the analysis |
Integer values of System.Runtime.InteropServices.DllImportSearchPath |
770 (that is, AssemblyDirectory | UseDllDirectoryForDependencies | ApplicationDirectory ) |
CA5393 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Exclude ASP.NET Core MVC ControllerBase when considering CSRF | true or false |
true |
CA5391 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies which paths to analyze for dispose violations | - AllPaths - Track and report missing dispose violations on all paths (non-exception and exception paths). Additionally, also flag use of non-recommended dispose patterns that might cause potential dispose leaks.- AllPathsOnlyNotDisposed - Track and report missing dispose violations on all paths (non-exception and exception paths). Do not flag use of non-recommended dispose patterns that might cause potential dispose leaks.- NonExceptionPaths - Track and report missing dispose violations only on non-exception program paths. Additionally, also flag use of non-recommended dispose patterns that might cause potential dispose leaks.- NonExceptionPathsOnlyNotDisposed - Track and report missing dispose violations only on non-exception program paths. Do not flag use of non-recommended dispose patterns that might cause potential dispose leaks. |
NonExceptionPaths |
CA2000 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Configure dispose ownership transfer for arguments passed to constructor invocation | true or false |
false |
CA2000 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Configure dispose ownership transfer for disposable objects passed as arguments to method calls | true or false |
false |
CA2000 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies the threshold to trigger the enum values naming rule | - AnyEnumValue - The rule is triggered if any of the enum values starts with the enum type name.- AllEnumValues - The rule is triggered if all of the enum values start with the enum type name.- Heuristic - The rule is triggered using the default FxCop heuristic (that is, when at least 75% of the enum values start with the enum type name). |
Heuristic |
CA1712 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Exclude indirect base types | true or false |
true |
CA1710 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies additional required suffixes | List of type names (separated by |) with their required suffix (separated by -> ). Allowed type name formats:- 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 | CA1710 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies additional required generic interfaces | List of interface names (separated by |) with their required generic fully qualified interface (separated by -> ). Allowed interface formats:- Interface name only (includes all interfaces 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 | CA1010 |
Examples:
Option Value | Summary |
---|---|
dotnet_code_quality.CA1010.additional_required_generic_interfaces = ISomething->System.Collections.Generic.IEnumerable`1 |
All types implementing ISomething regardless of its namespace are expected to also implement System.Collections.Generic.IEnumerable\`1 . |
dotnet_code_quality.CA1010.additional_required_generic_interfaces = T:System.Collections.IDictionary->T:System.Collections.Generic.IDictionary`2 |
All types implementing System.Collections.IDictionary are expected to also implement System.Collections.Generic.IDictionary`2 . |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies types or namespaces to exclude from the inheritance hierarchy tree | Allowed type name formats: - Type or namespace name (includes all types with the name, regardless of the containing type or namespace, and all types whose namespace contains the name). - Type or namespace name ending with a wildcard symbol (includes all types whose name starts with the given name, regardless of the containing type or namespace, and all types whose namespace contains the name). - Fully qualified names in the symbol's documentation ID format with an optional T: prefix for types or N: prefix for namespaces.- Fully qualified type or namespace name with an optional T: prefix for type or N: prefix for namespace and ending with the wildcard symbol (includes all types whose fully qualified name starts with the given type name, or all types whose fully qualified name starts with the given namespace name). |
N:System.* (This value is always automatically added to the value provided) |
CA1501 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies the symbol kinds to analyze | One or more fields of SymbolKind as a comma-separated list. | Namespace, NamedType, Method, Property, Event, Parameter |
CA1716 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Configures whether parameters or property names containing Text , Message , or Caption trigger this rule |
true or false |
false |
CA1303 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies additional custom APIs whose results must be used | Names of additional methods (separated by |). Allowed method name formats: - 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 | CA1806 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies allowable suffixes | List (separated by |) of allowed suffixes. | None | CA1711 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies whether to enable analysis for TFMs prior to .NET 5 | true or false |
false |
CA1416 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies whether to exclude structs from analysis | true or false |
false |
CA1051 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies additional allowable names for a zero-value enumeration field | List of additional names (separated by |). | None | CA1008 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies additional custom methods that enumerate an IEnumerable | Fully qualified names of additional methods (separated by |). | None | CA1851 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies additional customized LINQ chain methods (that is, methods take an IEnumerable argument and return a new IEnumerable instance) |
Fully qualified names of additional methods (separated by |). | None | CA1851 |
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies whether to assume that customized methods enumerate their IEnumerable parameters |
true or false |
false |
CA1851 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Training
Learning path
Implement finance and operations apps - Training
Plan and design your project methodology to successfully implement finance and operations apps with FastTrack services, data management and more.
Documentation
Configure code analysis rules - .NET
Learn how to configure code analysis rules in an analyzer configuration file.
Code quality rules overview - .NET
Learn about all of the available code quality rules for code analysis.
Code analysis rule categories - .NET
Learn the different .NET code analysis rule categories.