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
- try_determine_additional_string_formatting_methods_automatically
- unsafe_DllImportSearchPath_bits
- exclude_aspnet_core_mvc_controllerbase
- dispose_analysis_kind
- dispose_ownership_transfer_at_constructor
- dispose_ownership_transfer_at_method_call
- enum_values_prefix_trigger
- exclude_indirect_base_types
- additional_required_suffixes
- additional_required_generic_interfaces
- additional_inheritance_excluded_symbol_names
- analyzed_symbol_kinds
- use_naming_heuristic
- additional_use_results_methods
- allowed_suffixes
- enable_platform_analyzer_on_pre_net5_target
- exclude_structs
- additional_enum_none_names
- enumeration_methods
- linq_chain_methods
- assume_method_enumerates_parameters
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 |
try_determine_additional_string_formatting_methods_automatically
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 |
unsafe_DllImportSearchPath_bits
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 |
exclude_aspnet_core_mvc_controllerbase
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Exclude ASP.NET Core MVC ControllerBase when considering CSRF | true or false |
true |
CA5391 |
dispose_analysis_kind
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 |
dispose_ownership_transfer_at_constructor
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Configure dispose ownership transfer for arguments passed to constructor invocation | true or false |
false |
CA2000 |
dispose_ownership_transfer_at_method_call
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 |
enum_values_prefix_trigger
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 |
exclude_indirect_base_types
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Exclude indirect base types | true or false |
true |
CA1710 |
additional_required_suffixes
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 |
additional_required_generic_interfaces
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 . |
additional_inheritance_excluded_symbol_names
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 |
analyzed_symbol_kinds
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 |
use_naming_heuristic
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 |
additional_use_results_methods
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 |
allowed_suffixes
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies allowable suffixes | List (separated by |) of allowed suffixes. | None | CA1711 |
enable_platform_analyzer_on_pre_net5_target
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies whether to enable analysis for TFMs prior to .NET 5 | true or false |
false |
CA1416 |
exclude_structs
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies whether to exclude structs from analysis | true or false |
false |
CA1051 |
additional_enum_none_names
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 |
enumeration_methods
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 |
linq_chain_methods
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 |
assume_method_enumerates_parameters
Description | Allowable values | Default value | Configurable rules |
---|---|---|---|
Specifies whether to assume that customized methods enumerate their IEnumerable parameters |
true or false |
false |
CA1851 |