cc - Cyclomatic Complexity
Overview
The cc command calculates cyclomatic complexity for C# methods in your projects or directories. Cyclomatic complexity is a software metric that measures the number of linearly independent paths through a program’s source code, helping you identify overly complex methods that may be difficult to test and maintain.
Syntax
nmbl cc <ProjectFileOrDirectory>Arguments
ProjectFileOrDirectory- Path to a .csproj file or directory containing C# files
Output
Displays a table of methods with their cyclomatic complexity scores, ordered by complexity (highest first). This helps you quickly identify the most complex methods in your codebase.
Examples
Analyze a Specific Project
nmbl cc src/MyProject/MyProject.csprojCalculates complexity for all methods in the specified project.
Analyze All Projects in a Directory
nmbl cc src/Recursively analyzes all C# files in the directory tree.
Analyze Current Directory
nmbl cc .Analyzes all C# files in the current directory and subdirectories.
Understanding the Results
Methods with higher cyclomatic complexity scores are generally:
- Harder to understand
- More difficult to test
- More prone to bugs
- Good candidates for refactoring
Complexity Guidelines:
- 1-10: Simple, easy to understand
- 11-20: Moderate complexity, consider refactoring
- 21-50: High complexity, should be refactored
- 50+: Very high complexity, critical to refactor