CA1505: Avoid unmaintainable code

Value
Rule ID CA1505
Category Maintainability
Fix is breaking or non-breaking Non-breaking

Cause

A type or method has a low maintainability index value.

Rule description

The maintainability index is calculated by using the following metrics: lines of code, program volume, and cyclomatic complexity. Program volume is a measure of the difficulty of understanding of a type or method that's based on the number of operators and operands in the code. Cyclomatic complexity is a measure of the structural complexity of the type or method. You can learn more about code metrics at Measure complexity and maintainability of managed code.

A low maintainability index indicates that a type or method is probably difficult to maintain and would be a good candidate to redesign.

How to fix violations

To fix this violation, redesign the type or method and try to split it into smaller and more focused types or methods.

When to suppress warnings

You can suppress this warning when the type or method cannot be split or is considered maintainable despite its large size.

Suppress a warning

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

#pragma warning disable CA1505
// The code that's violating the rule is on this line.
#pragma warning restore CA1505

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

[*.{cs,vb}]
dotnet_diagnostic.CA1505.severity = none

To disable this entire category of rules, set the severity for the category to none in the configuration file.

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Maintainability.severity = none

For more information, see How to suppress code analysis warnings.

See also