Kaakati

Code Quality Gates

"Quality gate patterns including dart analysis, test coverage, build validation, and compliance checks"

Kaakati 9 Updated 4mo ago
GitHub

Install

npx skillscat add kaakati/rails-enterprise-dev/code-quality-gates

Install via the SkillsCat registry.

SKILL.md

Code Quality Gates

Gate 1: Dart Analysis

flutter analyze

Pass criteria: 0 errors

Configuration (analysis_options.yaml):

include: package:flutter_lints/flutter.yaml

analyzer:
  exclude:
    - "**/*.g.dart"
    - "**/*.freezed.dart"
  
  errors:
    invalid_annotation_target: ignore
    
linter:
  rules:
    - prefer_const_constructors
    - prefer_const_literals_to_create_immutables
    - avoid_print
    - avoid_unnecessary_containers
    - prefer_single_quotes
    - sort_child_properties_last

Gate 2: Test Coverage

# Run tests with coverage
flutter test --coverage

# Generate HTML report
genhtml coverage/lcov.info -o coverage/html

# Check coverage percentage
lcov --summary coverage/lcov.info

Pass criteria: โ‰ฅ 80% line coverage

Validation script:

#!/bin/bash
COVERAGE=$(lcov --summary coverage/lcov.info 2>&1 | grep "lines" | grep -oP '\d+\.\d+')

if (( $(echo "$COVERAGE >= 80.0" | bc -l) )); then
  echo "โœ… Coverage: $COVERAGE% (PASSED)"
  exit 0
else
  echo "โŒ Coverage: $COVERAGE% (FAILED - requires โ‰ฅ 80%)"
  exit 1
fi

Gate 3: Build Validation

# Debug build
flutter build apk --debug

# Release build (for production)
flutter build apk --release

Pass criteria: Build succeeds without errors

Gate 4: GetX Compliance

Check 1: Controllers use bindings

# Find controllers instantiated directly (anti-pattern)
grep -r "Get.put<.*Controller>" lib/presentation/pages/

# Should return 0 results (use bindings instead)

Check 2: Reactive variables use .obs

# Find reactive state declarations
grep -r "\.obs" lib/presentation/controllers/

# Verify all state is reactive

Check 3: Business logic in use cases

# Controllers should NOT call repositories directly
grep -r "Repository" lib/presentation/controllers/

# Should return 0 results

Gate 5: Clean Architecture Compliance

Check 1: Domain layer purity

# Domain should not import Flutter
grep -r "package:flutter" lib/domain/

# Should return 0 results

Check 2: Domain should not import GetX

grep -r "package:get" lib/domain/

# Should return 0 results

Check 3: Dependency flow validation

# Data can import domain (OK)
grep -r "import.*domain/" lib/data/

# Presentation can import data (OK)
grep -r "import.*data/" lib/presentation/

# Domain CANNOT import data or presentation
grep -r "import.*\(data\|presentation\)/" lib/domain/

# Should return 0 results

Automated Quality Gate Script

#!/bin/bash

echo "๐Ÿ” Running Quality Gates..."

# Gate 1: Dart Analysis
echo ""
echo "Gate 1: Dart Analysis"
flutter analyze
if [ $? -ne 0 ]; then
  echo "โŒ Dart analysis failed"
  exit 1
fi
echo "โœ… Dart analysis passed"

# Gate 2: Test Coverage
echo ""
echo "Gate 2: Test Coverage"
flutter test --coverage
COVERAGE=$(lcov --summary coverage/lcov.info 2>&1 | grep "lines" | grep -oP '\d+\.\d+')
if (( $(echo "$COVERAGE < 80.0" | bc -l) )); then
  echo "โŒ Coverage: $COVERAGE% (requires โ‰ฅ 80%)"
  exit 1
fi
echo "โœ… Coverage: $COVERAGE%"

# Gate 3: Build Validation
echo ""
echo "Gate 3: Build Validation"
flutter build apk --debug > /dev/null 2>&1
if [ $? -ne 0 ]; then
  echo "โŒ Build failed"
  exit 1
fi
echo "โœ… Build succeeded"

# Gate 4: GetX Compliance
echo ""
echo "Gate 4: GetX Compliance"
if grep -r "Get.put<.*Controller>" lib/presentation/pages/ > /dev/null 2>&1; then
  echo "โŒ Controllers instantiated directly (use bindings)"
  exit 1
fi
echo "โœ… GetX compliance passed"

# Gate 5: Clean Architecture
echo ""
echo "Gate 5: Clean Architecture"
if grep -r "package:flutter\|package:get" lib/domain/ > /dev/null 2>&1; then
  echo "โŒ Domain layer not pure"
  exit 1
fi
echo "โœ… Clean Architecture validated"

echo ""
echo "๐ŸŽ‰ All quality gates passed!"

CI/CD Integration

# .github/workflows/quality_gates.yml
name: Quality Gates

on: [push, pull_request]

jobs:
  quality:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v3
    
    - uses: subosito/flutter-action@v2
      with:
        flutter-version: '3.16.0'
    
    - name: Install dependencies
      run: flutter pub get
    
    - name: Run dart analyze
      run: flutter analyze
    
    - name: Run tests with coverage
      run: flutter test --coverage
    
    - name: Check coverage
      run: |
        sudo apt-get install lcov
        COVERAGE=$(lcov --summary coverage/lcov.info 2>&1 | grep "lines" | grep -oP '\d+\.\d+')
        if (( $(echo "$COVERAGE < 80.0" | bc -l) )); then
          echo "Coverage $COVERAGE% is below 80%"
          exit 1
        fi
    
    - name: Build APK
      run: flutter build apk --debug