Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 141 additions & 91 deletions docs/fundamentals/code-analysis/code-quality-rule-options.md

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions docs/fundamentals/code-analysis/includes/api-surface.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Include specific API surfaces

You can configure which parts of your codebase to run this rule on, based on their accessibility, by setting the [api_surface](../../code-quality-rule-options.md#api_surface) option. 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:

```ini
dotnet_code_quality.CAXXXX.api_surface = private, internal
```

> [!NOTE]
> Replace the `XXXX` part of `CAXXXX` with the ID of the applicable rule.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
### Configure dispose ownership transfer

The [dispose_ownership_transfer_at_constructor](../../code-quality-rule-options.md#dispose_ownership_transfer_at_constructor) and [dispose_ownership_transfer_at_method_call](../../code-quality-rule-options.md#dispose_ownership_transfer_at_method_call) options configure the transfer of dispose ownership.

For example, to specify that the rule transfers dispose ownership for arguments passed to constructors, add the following key-value pair to an *.editorconfig* file in your project:

```ini
dotnet_code_quality.CAXXXX.dispose_ownership_transfer_at_constructor = true
```

> [!NOTE]
> Replace the `XXXX` part of `CAXXXX` with the ID of the applicable rule.

#### dispose_ownership_transfer_at_constructor

Consider the following code example.

```csharp
class A : IDisposable
{
public void Dispose() { }
}

class Test
{
DisposableOwnerType M1()
{
return new DisposableOwnerType(new A());
}
}
```

- If `dotnet_code_quality.dispose_ownership_transfer_at_constructor` is set to `true`, dispose ownership for the `new A()` allocation is transferred to the returned `DisposableOwnerType` instance.
- If `dotnet_code_quality.dispose_ownership_transfer_at_constructor` is set to `false`, `Test.M1()` has the dispose ownership for `new A()`, and results in a `CA2000` violation for a dispose leak.

#### dispose_ownership_transfer_at_method_call

Consider the following code example.

```csharp
class Test
{
void M1()
{
TransferDisposeOwnership(new A());
}
}
```

- If `dotnet_code_quality.dispose_ownership_transfer_at_method_call` is set to `true`, dispose ownership for the `new A()` allocation is transferred to the `TransferDisposeOwnership` method.
- If `dotnet_code_quality.dispose_ownership_transfer_at_method_call` is set to `false`, `Test.M1()` has the dispose ownership for `new A()`, and results in a `CA2000` violation for a dispose leak.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Exclude specific symbols

You can exclude specific symbols, such as types and methods, from analysis. For example, to specify that the rule should not run on any code within types named `MyType`, add the following key-value pair to an *.editorconfig* file in your project:
You can exclude specific symbols, such as types and methods, from analysis by setting the [excluded_symbol_names](../../code-quality-rule-options.md#excluded_symbol_names) option. For example, to specify that the rule should not run on any code within types named `MyType`, add the following key-value pair to an *.editorconfig* file in your project:

```ini
dotnet_code_quality.CAXXXX.excluded_symbol_names = MyType
Expand All @@ -12,7 +12,7 @@ dotnet_code_quality.CAXXXX.excluded_symbol_names = MyType
Allowed symbol name formats in the option value (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](../../../csharp/language-reference/xmldoc/index.md#id-strings). Each symbol name requires a symbol-kind prefix, such as `M:` for methods, `T:` for types, and `N:` for namespaces.
- Fully qualified names in the symbol's [documentation ID format](../../../../csharp/language-reference/xmldoc/index.md#id-strings). Each symbol name requires a symbol-kind prefix, such as `M:` for methods, `T:` for types, and `N:` for namespaces.
- `.ctor` for constructors and `.cctor` for static constructors.

Examples:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Exclude specific types and their derived types

You can exclude specific types and their derived types from analysis. For example, to specify that the rule should not run on any methods within types named `MyType` and their derived types, add the following key-value pair to an *.editorconfig* file in your project:
You can exclude specific types and their derived types from analysis by setting the [excluded_type_names_with_derived_types](../../code-quality-rule-options.md#excluded_type_names_with_derived_types) option. For example, to specify that the rule should not run on any methods within types named `MyType` and their derived types, add the following key-value pair to an *.editorconfig* file in your project:

```ini
dotnet_code_quality.CAXXXX.excluded_type_names_with_derived_types = MyType
Expand All @@ -12,12 +12,12 @@ dotnet_code_quality.CAXXXX.excluded_type_names_with_derived_types = MyType
Allowed symbol name formats in the option value (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](../../../csharp/language-reference/xmldoc/index.md#id-strings), with an optional `T:` prefix.
- Fully qualified names in the symbol's [documentation ID format](../../../../csharp/language-reference/xmldoc/index.md#id-strings), with an optional `T:` prefix.

Examples:

<!-- markdownlint-disable MD056 -->
| Option Value | Summary |
| Option value | Summary |
| --- | --- |
|`dotnet_code_quality.CAXXXX.excluded_type_names_with_derived_types = MyType` | Matches all types named `MyType` and all of their derived types. |
|`dotnet_code_quality.CAXXXX.excluded_type_names_with_derived_types = MyType1|MyType2` | Matches all types named either `MyType1` or `MyType2` and all of their derived types. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Ignore InternalsVisibleTo attribute

By default, this rule is disabled if the assembly being analyzed uses <xref:System.Runtime.CompilerServices.InternalsVisibleToAttribute> to expose its internal symbols. You can set the [ignore_internalsvisibleto](../../code-quality-rule-options.md#ignore_internalsvisibleto) option to change the configuration. To specify that the rule should run even if the assembly is marked with <xref:System.Runtime.CompilerServices.InternalsVisibleToAttribute>, add the following key-value pair to an *.editorconfig* file in your project:

```ini
dotnet_code_quality.CAXXXX.ignore_internalsvisibleto = true
```

> [!NOTE]
> Replace the `XXXX` part of `CAXXXX` with the ID of the applicable rule.

This option is available starting in .NET 8.
12 changes: 0 additions & 12 deletions docs/fundamentals/code-analysis/includes/ignore-ivt.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1000.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules that it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Related rules

Expand Down
4 changes: 2 additions & 2 deletions docs/fundamentals/code-analysis/quality-rules/ca1001.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ Use the following options to configure which parts of your codebase to run this

These options can be configured for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[excluded-symbol-names](../includes/excluded-symbol-names.md)]
[!INCLUDE[excluded-symbol-names](../includes/config-options/excluded-symbol-names.md)]

[!INCLUDE[excluded-type-names-with-derived-types](../includes/excluded-type-names-with-derived-types.md)]
[!INCLUDE[excluded-type-names-with-derived-types](../includes/config-options/excluded-type-names-with-derived-types.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1002.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Related rules

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1003.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1005.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Related rules

Expand Down
5 changes: 3 additions & 2 deletions docs/fundamentals/code-analysis/quality-rules/ca1008.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ Use the following option to configure which parts of your codebase to run this r

- [Include specific API surfaces](#include-specific-api-surfaces)
- [Additional zero-value field names](#additional-zero-value-field-names)
- [additional_enum_none_names](../code-quality-rule-options.md#additional_enum_none_names)

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category (Design) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).
You can configure these options for just this rule, for all rules they apply to, or for all rules in this category ([Design](design-warnings.md)) that they apply to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

### Additional zero-value field names

Expand Down
4 changes: 2 additions & 2 deletions docs/fundamentals/code-analysis/quality-rules/ca1010.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Use the following options to configure which parts of your codebase to run this
- [Include specific API surfaces](#include-specific-api-surfaces)
- [Additional required generic interfaces](#additional-required-generic-interfaces)

You can configure these options for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).
You can configure these options for just this rule, for all rules they apply to, or for all rules in this category ([Design](design-warnings.md)) that they apply to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

### Additional required generic interfaces

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1012.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1021.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example 1

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1024.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1027.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1028.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1030.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1031.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Examples:
|`dotnet_code_quality.CA1031.disallowed_symbol_names = T:NS1.ExceptionType1|T:NS1.ExceptionType2` | Matches types named 'ExceptionType1' and 'ExceptionType2' with respective fully qualified names. |
<!-- markdownlint-enable MD056 -->

You can configure these options for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).
You can configure these options for just this rule, for all rules they apply to, or for all rules in this category ([Design](design-warnings.md)) that they apply to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1036.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1040.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1041.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1043.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1044.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1045.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category ([Design](design-warnings.md)) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example 1

Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/code-analysis/quality-rules/ca1046.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Use the following option to configure which parts of your codebase to run this r

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category (Design) that it applies to. For more information, see [Code quality rule configuration options](../code-quality-rule-options.md).

[!INCLUDE[api-surface](../includes/api-surface.md)]
[!INCLUDE[api-surface](../includes/config-options/api-surface.md)]

## Example 1

Expand Down
Loading