Skip to content

Document missing CAxxxx rules #27885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 25, 2022
Merged
41 changes: 41 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1419.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle' (code analysis)"
description: "Learn about code analysis rule CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- "ProvidePublicParameterlessSafeHandleConstructorAnalyzer"
- "CA1419"
helpviewer_keywords:
- "ProvidePublicParameterlessSafeHandleConstructorAnalyzer"
- "CA1419"
author: Youssef1313
---
# CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'

| | Value |
|-|-|
| **Rule ID** |CA1419|
| **Category** |[Interoperability](interoperability-warnings.md)|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

A concrete <xref:System.Runtime.InteropServices.SafeHandle> type requires a parameterless constructor that is at least as visible as the containing type.

## Rule description

Providing a public parameterless constructor for a type derived from <xref:System.Runtime.InteropServices.SafeHandle> enables better performance and usage with source-generated interop solutions.

## How to fix violations

Add a parameterless constructor to your type.

## When to suppress warnings

Do not suppress a warning from this rule.

## See also

- [Interoperability rules](interoperability-warnings.md)
- [Native interoperability best practices](../../../standard/native-interop/best-practices.md)
36 changes: 36 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1727.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "CA1727: Use PascalCase for named placeholders (code analysis)"
description: "Learn about code analysis rule CA1727: Use PascalCase for named placeholders"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- LoggerMessageDefineAnalyzer
- CA1727
helpviewer_keywords:
- CA1727
- LoggerMessageDefineAnalyzer
author: Youssef1313
---
# CA1727: Use PascalCase for named placeholders

| | Value |
|-|-|
| **Rule ID** |CA1727|
| **Category** |[Naming](naming-warnings.md)|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

A named placeholder used with <xref:Microsoft.Extensions.Logging.ILogger> is not PascalCase.

## Rule description

A named placeholder used with <xref:Microsoft.Extensions.Logging.ILogger> should be PascalCase, a naming convention where the first letter of each compound word in a name is capitalized.

## How to fix violations

Use PascalCase for named placeholders.

## When to suppress warnings

Do not suppress a warning from this rule.
41 changes: 41 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1842.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "CA1842: Do not use 'WhenAll' with a single task (code analysis)"
description: "Learn about code analysis rule CA1842: Do not use 'WhenAll' with a single task"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- "DoNotUseWhenAllOrWaitAllWithSingleArgument"
- "CA1842"
helpviewer_keywords:
- "DoNotUseWhenAllOrWaitAllWithSingleArgument"
- "CA1842"
author: Youssef1313
---
# CA1842: Do not use 'WhenAll' with a single task

| | Value |
|-|-|
| **Rule ID** |CA1842|
| **Category** |[Performance](performance-warnings.md)|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

<xref:System.Threading.Tasks.Task.WhenAll%2A> is called with a single task.

## Rule description

Using `WhenAll` with a single task may result in performance loss.

## How to fix violations

You should await or return the task instead.

## When to suppress warnings

Do not suppress a warning from this rule.

## See also

- [CA1843: Do not use 'WaitAll' with a single task](ca1843.md)
- [Performance rules](performance-warnings.md)
41 changes: 41 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1843.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "CA1843: Do not use 'WaitAll' with a single task (code analysis)"
description: "Learn about code analysis rule CA1843: Do not use 'WaitAll' with a single task"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- "DoNotUseWhenAllOrWaitAllWithSingleArgument"
- "CA1843"
helpviewer_keywords:
- "DoNotUseWhenAllOrWaitAllWithSingleArgument"
- "CA1843"
author: Youssef1313
---
# CA1843: Do not use 'WaitAll' with a single task

| | Value |
|-|-|
| **Rule ID** |CA1843|
| **Category** |[Performance](performance-warnings.md)|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

<xref:System.Threading.Tasks.Task.WaitAll%2A> is called with a single task.

## Rule description

Using `WaitAll` with a single task may result in performance loss.

## How to fix violations

You should await or return the task instead.

## When to suppress warnings

Do not suppress a warning from this rule.

## See also

- [CA1842: Do not use 'WhenAll' with a single task](ca1842.md)
- [Performance rules](performance-warnings.md)
46 changes: 46 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1848.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "CA1848: Use the LoggerMessage delegates (code analysis)"
description: "Learn about code analysis rule CA1848: Use the LoggerMessage delegates"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- "LoggerMessageDefineAnalyzer"
- "CA1848"
helpviewer_keywords:
- "LoggerMessageDefineAnalyzer"
- "CA1848"
author: Youssef1313
---
# CA1848: Use the LoggerMessage delegates

| | Value |
|-|-|
| **Rule ID** |CA1848|
| **Category** |[Performance](performance-warnings.md)|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

Use of [logger extension methods](xref:Microsoft.Extensions.Logging.LoggerExtensions), such as <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogInformation%2A> and <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogDebug%2A>.

## Rule description

For high-performance logging scenarios, use the <xref:Microsoft.Extensions.Logging.LoggerMessage> pattern.

## How to fix violations

Use `LoggerMessage` to fix violations of this rule.

<xref:Microsoft.Extensions.Logging.LoggerMessage> provides the following performance advantages over Logger extension methods:

- Logger extension methods require "boxing" (converting) value types, such as `int`, into `object`. The <xref:Microsoft.Extensions.Logging.LoggerMessage> pattern avoids boxing by using static <xref:System.Action> fields and extension methods with strongly typed parameters.
- Logger extension methods must parse the message template (named format string) every time a log message is written. <xref:Microsoft.Extensions.Logging.LoggerMessage> only requires parsing a template once when the message is defined.

## When to suppress warnings

Do not suppress a warning from this rule.

## See also

- [High-performance logging with LoggerMessage in ASP.NET Core](/aspnet/core/fundamentals/logging/loggermessage)
- [Performance rules](performance-warnings.md)
40 changes: 40 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca2017.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: "CA2017: Parameter count mismatch (code analysis)"
description: "Learn about code analysis rule CA2017: Parameter count mismatch"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- "LoggerMessageDefineAnalyzer"
- "CA2017"
helpviewer_keywords:
- "LoggerMessageDefineAnalyzer"
- "CA2017"
author: Youssef1313
---
# CA2017: Parameter count mismatch

| | Value |
|-|-|
| **Rule ID** |CA2017|
| **Category** |[Reliability](reliability-warnings.md)|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

The number of parameters supplied in the logging message template does not match the number of named placeholders.

## Rule description

This rule flags logger calls that have an incorrect number of message arguments.

## How to fix violations

Match the number of placeholders in the template format with the number of passed arguments.

## When to suppress warnings

Do not suppress a warning from this rule.

## See also

- [Reliability rules](reliability-warnings.md)
40 changes: 40 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca2253.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: "CA2253: Named placeholders should not be numeric values"
description: "Learn about code analysis rule CA2253: Named placeholders should not be numeric values"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- CA2253
- LoggerMessageDefineAnalyzer
helpviewer_keywords:
- LoggerMessageDefineAnalyzer
- CA2253
author: Youssef1313
---
# CA2253: Named placeholders should not be numeric values

| | Value |
| ----------------------------------- | ------------------------------------ |
| **Rule ID** | CA2253 |
| **Category** | [Usage](usage-warnings.md) |
| **Fix is breaking or non-breaking** | Non-breaking |

## Cause

A message placeholder consists of numeric characters only.

## Rule description

Named placeholders in the logging message template should not be comprised of only numeric characters.

## How to fix violations

Rename the numeric placeholder.

## When to suppress errors

Do not suppress a warning from this rule.

## See also

- [Usage warnings](usage-warnings.md)
40 changes: 40 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca2254.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: "CA2254: Template should be a static expression"
description: "Learn about code analysis rule CA2254: Template should be a static expression"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- CA2254
- LoggerMessageDefineAnalyzer
helpviewer_keywords:
- LoggerMessageDefineAnalyzer
- CA2254
author: Youssef1313
---
# CA2254: Template should be a static expression

| | Value |
| ----------------------------------- | ------------------------------------ |
| **Rule ID** | CA2254 |
| **Category** | [Usage](usage-warnings.md) |
| **Fix is breaking or non-breaking** | Non-breaking |

## Cause

A message template passed to a logger API is not constant.

## Rule description

The logging message template should not vary between calls.

## How to fix violations

Update the message template to be a constant expression.

## When to suppress errors

Do not suppress a warning from this rule.

## See also

- [Usage warnings](usage-warnings.md)
40 changes: 40 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca2256.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: "CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface"
description: "Learn about code analysis rule CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface"
ms.date: 01/19/2022
ms.topic: reference
f1_keywords:
- CA2256
- DynamicInterfaceCastableImplementationAnalyzer
helpviewer_keywords:
- DynamicInterfaceCastableImplementationAnalyzer
- CA2256
author: Youssef1313
---
# CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface

| | Value |
| ----------------------------------- | ------------------------------------ |
| **Rule ID** | CA2256 |
| **Category** | [Usage](usage-warnings.md) |
| **Fix is breaking or non-breaking** | Non-breaking |

## Cause

An interface with <xref:System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute> has a non-implemented member.

## Rule description

Types attributed with <xref:System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute> act as an interface implementation for a type that implements the `IDynamicInterfaceCastable` type. As a result, it must provide an implementation of all of the members defined in the inherited interfaces, because the type that implements `IDynamicInterfaceCastable` will not provide them otherwise.

## How to fix violations

Implement the missing interface members.

## When to suppress errors

Do not suppress a warning from this rule.

## See also

- [Usage warnings](usage-warnings.md)
Loading