[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Collapse]CodeRush
  System Requirements
  Improve Performance
 [Expand]Features by Language
 [Expand]Getting Started
 [Expand]How To
 [Expand]Coding Assistance
 [Expand]Navigation and Search Tools
 [Collapse]Static Code Analysis
  [Expand]Analyzers Library
   Code Metrics
   Spell Checker
 [Expand]Visualization Tools
 [Expand]Code Style Assistance
  Building Assistance
  Debugging Assistance
 [Expand]Refactoring Assistance
 [Expand]Unit Testing Assistance
 [Expand]Decompiling Tools
 [Expand]Configuration Options
 [Expand]Extensibility
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Code Metrics

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.

Expanded How to Enable

Do one of the following to enable the Code Metrics feature:

  • Check the Enable Code Metrics checkbox in the Editor | All Languages | Code Analysis | Code Metrics options page;

or

  • Click the Show metrics button in the CodeRush Visualize toolbar.

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.

Expanded Customization

You can configure each Code Metric's threshold value in the Editor | All Languages | Code Analysis | Code Metrics options page.

Expanded Hide Metrics if the Threshold is not Exceeded

CodeRush can hide the metric values in the code editor if the threshold is not exceeded. To customize this behavior:

  • Check the "Show Metric Icon only if metric exceeds defined threshold" checkbox in the Code Metrics options page.

  • Click Apply and OK to close the dialog and save the changes.

Expanded Treat Exceeding the Metric’s Threshold Value as a Code Issue

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.

  • Enable the "Use In Code Analysis" option for the Line Count metric.

  • Set the default threshold value to 5.

  • Click Apply and OK to close the dialog and save the changes.
  • Run Code Issues Analysis to find members whose metrics exceed the threshold. For this, switch to the Solution Explorer, right-click a project to invoke the context menu, and select the Run Code Issues Analysis menu item.

This action opens the Code Issues window.

Expanded Filter Code Metrics Diagnostics

  • Click the "Show filter editor" button from the bar at the top of the Code Issues window.

  • Specify the "Id Begins with CRR0040" condition in the filter editor and click OK.

As a result, a list of all members in which metric values exceed a defined threshold is displayed.

Is this topic helpful?​​​​​​​