Thursday, September 25, 2008

Code Metrics color vs. Code Analysis warnings – what’s the difference?

Recently I have read an interesting question on MSDN forums:
“Why the color indications in Code Metrics Results tool window (red/yellow/green) are not in sync with Code Analysis warnings generated (when corresponding CA rules such as AvoidUnmaintainableCode are enabled)?”

It appears, that when Code Analysis warnings are fired on certain methods, the expectation might be that those methods will be marked as red/yellow in Code Metrics Results window.

The expectation is incorrect, since the color indication in Code Metrics Results window relates only to maintainability index (as described on FxCop blog) and therefore corresponds only to AvoidUnmaintainableCode warnings. Other CA warnings (such as AvoidExcessiveComplexity) may or may not cause the maintainability index to go into red/yellow range; each rule warning is fired when individual metric value falls into rule-specific range (as described in this helpful post). Thus while there is some correlation between Maintainability rules and Code Metrics Results tool window color coding it is not one to one.

No comments: