Search code examples
visual-studio-2017roslyn-code-analysis

How to change Code analysis error CA1506 class coupling to "moderate maintainability"


I get this code analysis error for class coupling. The error message says:

'xxxxx' is coupled with 32 different types from 12 different namespaces. Rewrite or refactor the method to decrease its class coupling, or consider moving the method to one of the other types it is tightly coupled with. A class coupling above 40 indicates poor mainainability, a class coupling between 40 and 30 indicates moderate maintainability, and a class coupling below 30 indicates good maintainability.

Currently I get this error because it is trying to enforce a "... below 30 indicates good maintainability". Now I would like to change that to a "moderate maintainability", which I can have upto 40 class coupling and no more.

Now how do I change this? I search all over and couldn't find how to change this.


Solution

  • I don't think this is configurable. I'd strongly recommend simplifying your code. If you really don't want to do that, you can suppress the warning on specific types with

    #pragma warning disable CA1506
    
    // My type
    
    #pragma warning restore CA1506