coderushforroslyn-118143-static-code-analysis-code-metrics.md
Code Metrics is a set of measurements that allow developers to estimate code complexity.
The following Code Metrics are available:
| Name | Description |
|---|---|
| Maintenance Complexity | This metric is calculated as a total maintenance complexity value for all code elements in the member’s implementation. This value is from 0 to infinity and estimates maintaining the member’s code. Methods whose a maintenance complexity value is less than 100 are easier to maintain. If you have methods with a value of more than 300, consider refactoring them. Different code elements’ maintenance complexity values (local variable declarations, assignment statements, expressions in for loops, unary operator, etc.) are constant. |
| Cyclomatic Complexity | This metric measures the structural complexity of the code. It is calculated according to the number of different code paths in the program flow. A program with a complex control flow requires more tests to cover code and is less maintainable. |
| Line Count | The metric indicates the total number of lines the member occupies. Blank lines are also counted. |
Do one of the following to enable the Code Metrics feature:
or
Once this feature is enabled, CodeRush shows metrics to the left of a member declaration in the code editor.
You should click the metric number and use the menu to select a different code metric.
You can configure each Code Metric’s threshold value in the Editor | All Languages | Code Analysis | Code Metrics options page.
CodeRush can hide the metric values in the code editor if the threshold is not exceeded. To customize this behavior:
Follow the steps below to customize this behavior for a member whose line count exceed the defined threshold value.
For example, the AddRecord method has 7 lines. The threshold value is 5.
Open the Code Metrics options page.
Make sure the Line Count metric is active.
This action opens the Code Issues window.
As a result, a list of all members in which metric values exceed a defined threshold is displayed.