cogc - Cognitive Complexity

Overview

The cogc command calculates cognitive complexity for C# code. Unlike cyclomatic complexity which measures structural complexity, cognitive complexity measures how difficult code is for humans to understand. It takes into account nesting, breaks in linear flow, and other factors that affect readability.

Syntax

nmbl cogc <ProjectFileOrDirectory>

Arguments

Output

Displays cognitive complexity scores for methods in your code, helping you identify methods that are difficult to understand and maintain.

Examples

Analyze a Specific Project

nmbl cogc src/MyProject/MyProject.csproj

Calculates cognitive complexity for all methods in the project.

Analyze a Directory

nmbl cogc src/Services/

Analyzes all C# files in the Services directory.

Compare with Cyclomatic Complexity

# First check cyclomatic complexity
nmbl cc src/MyProject/MyProject.csproj

# Then check cognitive complexity
nmbl cogc src/MyProject/MyProject.csproj

Comparing both metrics gives you a complete picture of code complexity.

Understanding Cognitive Complexity

Cognitive complexity differs from cyclomatic complexity by:

Complexity Guidelines: