Code Quality Analysis
The EmbedOps CLI provides comprehensive code quality analysis capabilities for embedded systems projects, supporting C, C++, Python, Go, and Rust.
Overview
The eo report codequality command analyzes your codebase and generates detailed metrics including:
- Cyclomatic Complexity: Measures code complexity based on control flow
- Lines of Code (LOC): Total, logical, and comment line counts
- Coupling: Efferent coupling measuring dependencies
- Cohesion (LCOM): Lack of Cohesion of Methods metric
- Health Score: Composite quality score (0-100%)
Quick Start
Basic Usage
# Analyze current directory and upload to EmbedOps
eo report codequality .
# Analyze specific directory
eo report codequality ./src
# Local analysis only (no upload)
eo report codequality ./src --local
# Filter by language
eo report codequality ./src --language go
Output Options
# Save to custom file
eo report codequality ./src --local --output quality-report.json
# Verbose output with file-by-file details
eo report codequality ./src --verbose
Command Reference
Syntax
Flags
Basic Flags
| Flag | Description | Default |
|---|---|---|
--language |
Filter to specific language (c, cpp, python, go, rust) | All languages |
--local, -l |
Run locally without uploading to EmbedOps | false |
--output, -o |
Output file path for local reports | ./code-quality-report.json |
--verbose, -v |
Enable verbose output with file-by-file metrics | false |
Complexity Thresholds
| Flag | Description | Default |
|---|---|---|
--complexity-excellent |
Complexity threshold for excellent quality | 10 |
--complexity-good |
Complexity threshold for good quality | 20 |
--complexity-warning |
Complexity threshold for warning | 30 |
Lines of Code Thresholds
| Flag | Description | Default |
|---|---|---|
--loc-excellent |
LOC threshold for excellent quality | 200 |
--loc-good |
LOC threshold for good quality | 500 |
--loc-warning |
LOC threshold for warning | 1000 |
Cohesion (LCOM) Thresholds
| Flag | Description | Default |
|---|---|---|
--lcom-excellent |
LCOM % threshold for excellent quality | 40 |
--lcom-good |
LCOM % threshold for good quality | 65 |
--lcom-warning |
LCOM % threshold for warning | 80 |
Coupling Thresholds
| Flag | Description | Default |
|---|---|---|
--coupling-excellent |
Coupling threshold for excellent quality | 5 |
--coupling-good |
Coupling threshold for good quality | 10 |
--coupling-warning |
Coupling threshold for warning | 15 |
Examples
Standard Analysis
Output:
Analyzing Code Quality...
══════════════════════════════════════════════════════════════════════
Overall Health: 81% (Excellent)
──────────────────────────────────────────────────────────────────────
Analyzed: 42 files | 10,696 LOC | 328 functions | Avg Complexity: 36.6
──────────────────────────────────────────────────────────────────────
Quality Distribution:
🟢 Excellent: 21 files (50%)
🟡 Good: 16 files (38%)
🟠 Warning: 5 files (12%)
🔴 Critical: 0 files (0%)
══════════════════════════════════════════════════════════════════════
Custom Thresholds
# Use stricter thresholds
eo report codequality ./src \
--complexity-excellent 5 \
--complexity-good 10 \
--complexity-warning 15 \
--loc-excellent 100 \
--loc-good 250 \
--loc-warning 500
Language-Specific Analysis
# Analyze only Go code
eo report codequality ./src --language go
# Analyze only C/C++ code
eo report codequality ./src --language c
eo report codequality ./src --language cpp
Local Analysis with Verbose Output
# Generate detailed report locally
eo report codequality ./src --local --verbose --output detailed-report.json
Verbose output includes: - File-by-file metrics - Function-level complexity - Detailed health calculations - Line count breakdowns
JSON Output Format
The generated JSON report contains (all percentage metrics are expressed as decimals 0-100):
{
"summary": {
"OverallHealth": 81.07,
"TotalFiles": 42,
"TotalLOC": 10696,
"AvgComplexity": 36.6,
"FunctionsAnalyzed": 328,
"Distribution": {
"Excellent": 21,
"Good": 16,
"Warning": 5,
"Critical": 0
},
"TopIssues": [
{
"Path": "src/complex.go",
"Health": 53.46,
"Complexity": 149,
"LCOM": 0
}
]
},
"file_metrics": [
{
"FilePath": "src/example.go",
"Language": "go",
"Health": 85.5,
"Metrics": {
"Complexity": 12,
"LOC": 150,
"LogicalLOC": 120,
"CommentLOC": 30,
"LCOM": 0.25,
"Coupling": 3,
"Functions": 8
},
"Functions": [
{
"Name": "ProcessData",
"Complexity": 5,
"LOC": 25,
"StartLine": 10,
"EndLine": 35
}
]
}
]
}
Health Scoring Algorithm
The health score is calculated using weighted factors:
Health Score = 100% - (
0.35 × Complexity_Factor +
0.25 × Coupling_Factor +
0.25 × LCOM_Factor +
0.15 × LOC_Factor
)
Where each factor is calculated based on how far the metric exceeds the configured thresholds.
Quality Categories
| Health Score | Category | Description |
|---|---|---|
| 80-100% | 🟢 Excellent | Well-structured, maintainable code |
| 60-79% | 🟡 Good | Acceptable quality with minor issues |
| 40-59% | 🟠 Warning | Needs attention and refactoring |
| 0-39% | 🔴 Critical | Serious quality issues requiring immediate action |
Supported Languages
Go
- Full AST-based complexity analysis
- Package-level coupling detection
- Method cohesion analysis
C/C++
- Function-level complexity (via external tools)
- Include-based coupling analysis
- Basic cohesion metrics
Python
- Function and class complexity
- Import-based coupling
- Class cohesion metrics
Rust
- Function complexity analysis
- Use-statement coupling
- Module cohesion
Integration with EmbedOps Platform
When not using --local flag, the analysis results are automatically uploaded to the EmbedOps Platform where you can:
- View historical quality trends
- Compare quality across branches
- Explore interactive treemap visualizations
- Set custom quality thresholds per repository
- Receive quality alerts in CI/CD pipelines
CI/CD Integration
Add to your CI pipeline:
# .github/workflows/quality.yml
name: Code Quality
on: [push, pull_request]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install EmbedOps CLI
run: curl -sSL https://embedops.com/install.sh | sh
- name: Analyze Code Quality
env:
EO_API_KEY: ${{ secrets.EO_API_KEY }}
run: eo report codequality ./src
Troubleshooting
"No files found to analyze"
- Verify the source directory path is correct
- Check that the directory contains supported file types
- Use
--verboseto see which files are being discovered
"Failed to analyze complexity"
- Ensure required external tools are installed:
- For C/C++:
lizard - For Go:
gocyclo - For Python:
radon - Check file encoding (UTF-8 recommended)
High LCOM values
LCOM (Lack of Cohesion of Methods) measures how well methods in a file work together: - 0-40%: Highly cohesive (excellent) - 40-65%: Moderately cohesive (good) - 65-80%: Low cohesion (warning) - 80-100%: Very low cohesion (critical)
Consider refactoring files with high LCOM by: - Splitting into smaller, focused modules - Grouping related functionality - Reducing unnecessary dependencies
Best Practices
- Run regularly: Integrate into CI/CD to track quality over time
- Set realistic thresholds: Adjust based on your project's complexity
- Focus on trends: Monitor changes rather than absolute values
- Address hotspots first: Focus on files with lowest health scores
- Review critical files: Pay special attention to 🔴 critical files
- Use language filters: Analyze specific languages for targeted improvements