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:
Depth of Inheritance
Warning at above 5 levels deep
Warning at above 25
Warning at below 20
Warning at above 80 for class and above 30 for a method
In the policy editor this would look like the following:
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.