|
| 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) |
0 commit comments