Code Metrics as Check-in Policy

This is the first in a series of posts around questions I am getting asked related to code metrics.

One question that is coming up is:

Can a check-in policy be defined based on code metrics in TFS?

Well, code metrics itself does not have a check-in policy but fortunately the Maintainability Index, Class Coupling, Depth of Inheritance and Complexity metrics are all available as rules in Code Analysis in Visual Studio.  This means you can use code analysis check-in policy enabled with those rules.  The rules are grouped under the “Maintainability Rules” Category and are configured as follows:

Metric Corresponding Rule Threshold
Depth of Inheritance CA1501 AvoidExcessiveInheritance Warning at above 5 levels deep
Complexity CA1502 AvoidExcessiveComplexity Warning at above 25

Maintainability Index

CA1505 AvoidUnmaintainableCode Warning at below 20
Class Coupling CA1506 AvoidExcessiveClassCoupling

Warning at above 80 for class and above 30 for a method

In the policy editor this would look like the following:

Code Metrics as a check-in policy

This allows you to enforce that code meets these thresholds before check-in.  In future we are looking in to allowing the threshold values to be changed.

Comments (10)

  1. Time for another weekly round-up of developer news that focuses on .NET, agile and general development

  2. What else can I say? The big day has arrived (read the official word here on Soma’s blog ) and we’re

  3. The Visual Studio Code Analysis Team Blog on Code Metrics as Check-In Policy and Code Metrics Customization….

  4. In previous posts about Code Metrics and Code Reviews , I explored some metrics and techniques that I

  5. naisioxerloro says:


    Good design, who make it?

  6. Como muchos ya sabréis hace poco Microsoft lanzó al mercado Visual Studio 2008. Si estáis

  7. So I have had at least a half dozen customers ask about this recently, and found a great article on the

  8. Como muchos ya sabréis hace poco Microsoft lanzó al mercado Visual Studio 2008. Si estáis interesados

  9. [ Nacsa Sándor , 2009. január 19. – február 5.] Ez a Team System változat fejlett eszközrendszert kínál