Skip to content

Commit 4d268d2

Browse files
authored
Merge pull request #6477 from mavasani/Doc_CA1509
Add documentation for CA1509 (Invalid entry in code metrics configura…
2 parents 525bce7 + f5639db commit 4d268d2

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

docs/code-quality/ca1509.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: 'CA1509: Invalid entry in code metrics configuration file'
3+
ms.date: 04/28/2020
4+
ms.topic: reference
5+
f1_keywords:
6+
- CA1509
7+
- CodeMetricsAnalyzer
8+
helpviewer_keywords:
9+
- CodeMetricsAnalyzer
10+
- CA1509
11+
author: mavasani
12+
ms.author: mavasani
13+
manager: jillfra
14+
ms.workload:
15+
- multiple
16+
---
17+
# CA1509: Invalid entry in code metrics configuration file
18+
19+
|||
20+
|-|-|
21+
|TypeName|CodeMetricsAnalyzer|
22+
|CheckId|CA1509|
23+
|Category|Microsoft.Maintainability|
24+
|Breaking change|Non-Breaking|
25+
26+
## Cause
27+
28+
Code metrics rules, such as [CA1501](ca1501.md), [CA1502](ca1502.md), [CA1505](ca1505.md) and [CA1506](ca1506.md), supplied a configuration file named `CodeMetricsConfig.txt` that has an invalid entry.
29+
30+
## Rule description
31+
32+
[FxCop analyzers](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers) implementation of [code metrics](code-metrics-values.md) analysis rules allow end users to supply an [additional file](https://github.com/dotnet/roslyn/blob/release/dev16.6/docs/analyzers/Using%20Additional%20Files.md) named `CodeMetricsConfig.txt`. This file contains entries to configure code metric thresholds for analysis. Following rules are configurable in this file:
33+
34+
- [CA1501: Avoid excessive inheritance](ca1501.md)
35+
- [CA1502: Avoid excessive complexity](ca1502.md)
36+
- [CA1505: Avoid unmaintainable code](ca1505.md)
37+
- [CA1506: Avoid excessive class coupling](ca1506.md)
38+
39+
This configuration file expects each entry to be in following format:
40+
41+
```ini
42+
'RuleId'(Optional 'SymbolKind'): 'Threshold'
43+
```
44+
45+
- Valid values for 'RuleId' are `CA1501`, `CA1502`, `CA1505` and `CA1506`.
46+
- Valid values for optional 'SymbolKind' are `Assembly`, `Namespace`, `Type`, `Method`, `Field`, `Event`, and `Property`.
47+
- Valid values for 'Threshold' are non-negative integers.
48+
- Lines starting with '#' are treated as comment lines
49+
50+
For example, the following is a valid configuration file:
51+
52+
```ini
53+
# Comment text
54+
55+
CA1501: 1
56+
57+
CA1502(Type): 4
58+
CA1502(Method): 2
59+
```
60+
61+
An invalid entry in this configuration file is flagged with the `CA1509` diagnostic.
62+
63+
> [!NOTE]
64+
> Rule CA1509 is not available in legacy analysis. It was first introduced in [FxCop analyzers](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers) version 2.9.6.
65+
66+
67+
## How to fix violations
68+
69+
To fix a violation of this rule, make sure the invalid entry in `CodeMetricsConfig.txt` gets the required format.
70+
71+
## When to suppress warnings
72+
73+
Do not suppress violations of this rule.
74+
75+
## Related rules
76+
77+
- [CA1501: Avoid excessive inheritance](ca1501.md)
78+
- [CA1502: Avoid excessive complexity](ca1502.md)
79+
- [CA1505: Avoid unmaintainable code](ca1505.md)
80+
- [CA1506: Avoid excessive class coupling](ca1506.md)
81+
82+
## See also
83+
84+
- [Maintainability warnings](maintainability-warnings.md)
85+
- [Measure complexity and maintainability of managed code](code-metrics-values.md)

docs/code-quality/code-analysis-warnings-for-managed-code-by-checkid.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ f1_keywords:
107107
- CA1506
108108
- CA1507
109109
- CA1508
110+
- CA1509
110111
- CA1600
111112
- CA1601
112113
- CA1700
@@ -377,6 +378,7 @@ The following table lists Code Analysis warnings for managed code by the CheckId
377378
| CA1506 | [CA1506: Avoid excessive class coupling](../code-quality/ca1506.md) | This rule measures class coupling by counting the number of unique type references that a type or method contains. |
378379
| CA1507 | [CA1507: Use nameof in place of string](../code-quality/ca1507.md) | A string literal is used as an argument where a `nameof` expression could be used. |
379380
| CA1508 | [CA1508: Avoid dead conditional code](../code-quality/ca1508.md) | A method has conditional code that always evaluates to `true` or `false` at runtime. This leads to dead code in the `false` branch of the condition. |
381+
| CA1509 | [CA1509: Invalid entry in code metrics configuration file](../code-quality/ca1509.md) | Code metrics rules, such as [CA1501](ca1501.md), [CA1502](ca1502.md), [CA1505](ca1505.md) and [CA1506](ca1506.md), supplied a configuration file named `CodeMetricsConfig.txt` that has an invalid entry. |
380382
| CA1600 | [CA1600: Do not use idle process priority](../code-quality/ca1600.md) | Do not set process priority to Idle. Processes that have System.Diagnostics.ProcessPriorityClass.Idle will occupy the CPU when it would otherwise be idle, and will therefore block standby. |
381383
| CA1601 | [CA1601: Do not use timers that prevent power state changes](../code-quality/ca1601.md) | Higher-frequency periodic activity will keep the CPU busy and interfere with power-saving idle timers that turn off the display and hard disks. |
382384
| CA1700 | [CA1700: Do not name enum values 'Reserved'](../code-quality/ca1700.md) | This rule assumes that an enumeration member that has a name that contains "reserved" is not currently used but is a placeholder to be renamed or removed in a future version. Renaming or removing a member is a breaking change. |

docs/code-quality/maintainability-warnings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Maintainability warnings support library and application maintenance.
3131
| [CA1506: Avoid excessive class coupling](../code-quality/ca1506.md) | This rule measures class coupling by counting the number of unique type references that a type or method contains. |
3232
| [CA1507: Use nameof in place of string](../code-quality/ca1507.md) | A string literal is used as an argument where a `nameof` expression could be used. |
3333
| [CA1508: Avoid dead conditional code](../code-quality/ca1508.md) | A method has conditional code that always evaluates to `true` or `false` at runtime. This leads to dead code in the `false` branch of the condition. |
34+
| [CA1509: Invalid entry in code metrics configuration file](../code-quality/ca1509.md) | Code metrics rules, such as [CA1501](ca1501.md), [CA1502](ca1502.md), [CA1505](ca1505.md) and [CA1506](ca1506.md), supplied a configuration file named `CodeMetricsConfig.txt` that has an invalid entry. |
3435

3536
## See also
3637

docs/code-quality/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@
432432
href: ca1507.md
433433
- name: "CA1508: Avoid dead conditional code"
434434
href: ca1508.md
435+
- name: "CA1509: Invalid entry in code metrics configuration file"
436+
href: ca1509.md
435437
- name: Mobility warnings
436438
items:
437439
- name: Overview

0 commit comments

Comments
 (0)