kakadesachin
kakadesachin

Reputation: 1

How to set cyclomatic complexity limit for specific method?

We have a codebase which is 20 years old running on .NET framework 4.8, and we have a requirement to add a code analyzer to a check for cyclomatic complexity in our source code and fail a build pipeline if the complexity is beyond a limit.

I use Microsoft.CodeAnalysis.NetAnalyzer and configured it to throw an error for cyclomatic complexity beyond 20, but for some methods we want to set a different threshold.

I see SuppressMessage attributes available, but that doesn't take in a parameter for a custom limit.

Is there another approach to this?

Upvotes: 0

Views: 210

Answers (1)

Bouam K
Bouam K

Reputation: 463

You can add a threshold for complexity, but it's on project level:

1-Crete a text file : CodeMetricsConfig.txt

2-Choose your treshold : CA1502: 20

3-Add this file in your project and mark it in properties as AdditionalFiles

For more infos take a look at this link : https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1502

Upvotes: 0

Related Questions