Skip to content

vt-c-quality-metrics

Track and analyze code quality metrics including coverage, complexity, duplication, and trends over time. Essential for identifying quality regressions before they become problems.

Plugin: core-standards
Category: Other
Command: /vt-c-quality-metrics


Quality Metrics Skill

Purpose: Measure and track code quality to catch regressions early and guide improvement efforts. You can't improve what you don't measure.

Core Metrics

1. Test Coverage

Target: 80%+ line coverage, 70%+ branch coverage

# JavaScript/TypeScript (Istanbul/nyc)
npx nyc --reporter=text --reporter=html npm test

# Python (pytest-cov)
pytest --cov=src --cov-report=html

# Ruby (SimpleCov)
# Add to spec_helper.rb
require 'simplecov'
SimpleCov.start 'rails'

Coverage Report Template:

## Coverage Report

| Metric | Current | Target | Status |
|--------|---------|--------|--------|
| Line coverage | 85% | 80% | ✅ |
| Branch coverage | 72% | 70% | ✅ |
| Function coverage | 90% | 80% | ✅ |

### Low Coverage Areas
| File | Coverage | Reason |
|------|----------|--------|
| `auth/oauth.ts` | 45% | Complex OAuth flow, needs integration tests |
| `utils/parser.ts` | 60% | Edge cases not covered |

### Action Items
- [ ] Add tests for OAuth refresh token flow
- [ ] Add tests for parser edge cases

2. Cyclomatic Complexity

Target: < 10 per function, < 20 per file

# JavaScript/TypeScript (ESLint)
# eslint.config.js
{
  rules: {
    'complexity': ['warn', 10]
  }
}

# Python (radon)
radon cc src/ -a -s

# Ruby (Flog)
flog app/

Complexity Guidelines: | Score | Interpretation | Action | |-------|---------------|--------| | 1-5 | Simple, low risk | None needed | | 6-10 | Moderate | Consider simplifying | | 11-20 | Complex | Should refactor | | 21+ | Very complex | Must refactor |

3. Code Duplication

Target: < 3% duplicate code

# JavaScript/TypeScript (jscpd)
npx jscpd src/ --threshold 3

# Python (CPD via PMD)
pmd cpd --minimum-tokens 100 --files src/

# Ruby (Flay)
flay app/

Duplication Report Template:

## Duplication Analysis

**Overall:** 2.1% duplication (target: < 3%) ✅

### Significant Duplicates
| Files | Lines | Tokens | Action |
|-------|-------|--------|--------|
| `userService.ts``adminService.ts` | 45 | 312 | Extract to shared module |
| `validator.ts` (3 locations) | 20 | 150 | Create utility function |

4. Maintainability Index

Target: > 65 (0-100 scale)

# JavaScript/TypeScript
npx es6-plato -d report src/

# Python
radon mi src/ -s

Maintainability Scale: | Score | Rating | Description | |-------|--------|-------------| | 85-100 | Excellent | Easy to maintain | | 65-84 | Good | Maintainable | | 40-64 | Moderate | Difficult to maintain | | 0-39 | Poor | Very difficult to maintain |

5. Technical Debt

Estimation methods:

## Technical Debt Inventory

| Item | Type | Effort | Priority |
|------|------|--------|----------|
| Legacy auth system | Architecture | 2 weeks | High |
| Missing TypeScript types in utils/ | Types | 3 days | Medium |
| No error boundaries in React | Reliability | 1 day | High |
| Outdated dependencies | Security | 2 days | High |

**Total estimated debt:** ~3 weeks of work
**Recommended allocation:** 20% of sprint capacity

Trend Tracking

Quality Dashboard Template

## Quality Metrics Dashboard

### Current Sprint

| Metric | Start | Current | Target | Trend |
|--------|-------|---------|--------|-------|
| Coverage | 78% | 82% | 80% | 📈 |
| Complexity (avg) | 8.2 | 7.5 | < 10 | 📈 |
| Duplication | 4.1% | 3.2% | < 3% | 📈 |
| Maintainability | 62 | 68 | > 65 | 📈 |
| Open bugs | 12 | 8 | < 10 | 📈 |

### 4-Week Trend
Coverage: ████████████████░░░░ 78% → 82% Complexity: ███████░░░░░░░░░░░░░ 8.2 → 7.5 Duplication: ████░░░░░░░░░░░░░░░░ 4.1% → 3.2%
### Areas Needing Attention
1. `src/legacy/` - Low coverage (45%), high complexity
2. `src/utils/parser.ts` - Complexity 25, needs refactor
3. `src/services/` - 5% duplication

Historical Comparison

## Quality Over Time

| Month | Coverage | Complexity | Debt (days) |
|-------|----------|------------|-------------|
| Jan | 75% | 9.1 | 25 |
| Feb | 78% | 8.5 | 22 |
| Mar | 80% | 8.2 | 18 |
| Apr | 82% | 7.5 | 15 |

**Observations:**
- Coverage improving steadily (+7% over 4 months)
- Complexity reduced through refactoring
- Technical debt being actively addressed

CI Integration

Quality Gates in CI

# .github/workflows/quality.yml
name: vt-c-quality-metrics

on: [push, pull_request]

jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Run tests with coverage
        run: npm test -- --coverage

      - name: Check coverage threshold
        run: |
          COVERAGE=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')
          if (( $(echo "$COVERAGE < 80" | bc -l) )); then
            echo "Coverage $COVERAGE% is below 80% threshold"
            exit 1
          fi

      - name: Check complexity
        run: npx eslint src/ --rule 'complexity: [error, 10]'

      - name: Check duplication
        run: npx jscpd src/ --threshold 3

      - name: Upload reports
        uses: actions/upload-artifact@v3
        with:
          name: quality-reports
          path: |
            coverage/
            .jscpd/

PR Quality Report

# Add to PR comment
- name: Comment quality metrics
  uses: actions/github-script@v6
  with:
    script: |
      const report = `
      ## Quality Metrics

      | Metric | Value | Status |
      |--------|-------|--------|
      | Coverage | ${coverage}% | ${coverage >= 80 ? '✅' : '❌'} |
      | Complexity | ${complexity} | ${complexity < 10 ? '✅' : '❌'} |
      | Duplication | ${duplication}% | ${duplication < 3 ? '✅' : '❌'} |
      `;
      github.rest.issues.createComment({
        issue_number: context.issue.number,
        owner: context.repo.owner,
        repo: context.repo.repo,
        body: report
      });

Review Integration

Pre-Review Checklist

## Quality Review Checklist

Before approving:

### Test Coverage
- [ ] New code has tests
- [ ] Coverage didn't decrease
- [ ] Critical paths covered

### Complexity
- [ ] No functions > 10 complexity
- [ ] Complex logic documented
- [ ] Consider splitting large functions

### Duplication
- [ ] No copy-pasted code
- [ ] Shared logic extracted
- [ ] Utilities used appropriately

### Maintainability
- [ ] Code is readable
- [ ] Names are descriptive
- [ ] Comments explain "why" not "what"

Improvement Strategies

When Coverage is Low

1. **Prioritize by risk**
   - Critical paths first
   - User-facing features
   - Security-sensitive code

2. **Start with integration tests**
   - Cover happy paths
   - Add edge cases incrementally

3. **Set incremental targets**
   - Week 1: 60% → 65%
   - Week 2: 65% → 70%
   - etc.

When Complexity is High

1. **Extract methods**
   - One thing per function
   - Descriptive names

2. **Simplify conditionals**
   - Early returns
   - Guard clauses
   - Polymorphism over switches

3. **Reduce nesting**
   - Maximum 3 levels
   - Extract nested logic

When Duplication is High

1. **Identify patterns**
   - Same logic, different data? → Parameterize
   - Same structure? → Extract template/base class

2. **Create utilities**
   - Common operations
   - Shared validators
   - Helper functions

3. **DRY vs WET balance**
   - Don't over-abstract
   - Rule of three: abstract after 3 duplicates

Resources