Skip to content

9-Gate Quality System

The quality gate system enforces code quality through 9 sequential checks. Each gate validates a specific aspect of code quality, from basic syntax to dependency security.

Gate Overview

GateNameToolsThresholdFail Behavior
1Syntax Validationpython3 ast, node --check, go build, bash -nZero errorsBlocking
2Lintingruff, oxlint/eslint, golangci-lint, shellcheck, clippyZero errorsBlocking
3Type Safetyty/mypy/pyright, tsc, go vetZero errorsBlocking
4Testspytest, vitest/jest, go test, cargo testAll passBlocking
5Coveragepytest-cov, go test -cover>=80%Blocking
6Securitybandit, gosec, gitleaks, npm auditZero high/criticalBlocking
7Complexityradon, ruff C901, gocycloCC<=10, Cog<=15Blocking
8Duplicationjscpd<5%Blocking
9Dependenciespip-audit, npm audit, govulncheck, cargo-auditZero vulnerabilitiesBlocking

Gate Details

Gate 1: Syntax Validation (Fast-Fail)

Catches parse errors before any other analysis runs.

  • Python: ast.parse() on each changed .py file
  • JavaScript/TypeScript: node --check on each changed file
  • Go: go build ./... for compile errors
  • Rust: cargo check for compile errors
  • Shell: bash -n for syntax validation

Fix: Correct the syntax error shown in the output.

Gate 2: Linting

Enforces code style and catches common mistakes.

LanguageToolConfig
Pythonruffruff.toml or pyproject.toml
JS/TSoxlint (preferred) or eslintoxlintrc.json or .eslintrc
Gogolangci-lint.golangci.yml
Shellshellcheck.shellcheckrc
Rustclippyclippy.toml

Fix: Run ruff check --fix, oxlint --fix, or the appropriate fixer.

Gate 3: Type Safety

Static type analysis to catch type errors before runtime.

LanguageToolConfig
Pythonty (preferred), mypy, pyrightty-config.toml, mypy.ini
TypeScripttsctsconfig.json
Gogo vetBuilt-in

Fix: Add type annotations, fix type mismatches, or update type stubs.

Gate 4: Tests

Runs the project test suite.

LanguageToolCommand
Pythonpytestpytest -q --tb=short
JS/TSvitest or jestnpx vitest run or npx jest
Gogo testgo test ./... -count=1
Rustcargo testcargo test --quiet

Fix: Fix failing tests. Do not skip or disable them.

Gate 5: Coverage (>=80%)

Ensures adequate test coverage. Threshold is configurable in quality-gate.yml.

LanguageToolReport
Pythonpytest-cov--cov --cov-report=term-missing
Gogo test -coverBuilt-in

Fix: Add tests for uncovered code paths. Focus on critical business logic first.

Gate 6: Security

Multi-layer security scanning.

LayerToolScope
SecretsgitleaksAll files (detects API keys, passwords)
SASTbandit (Python), gosec (Go)Source code analysis
Auditnpm auditNode dependency vulnerabilities

Fix: Remove secrets from code (use env vars), fix SAST findings, update vulnerable deps.

Gate 7: Complexity (CC<=10, Cognitive<=15)

Prevents overly complex functions that are hard to test and maintain.

MetricMaxTool
Cyclomatic complexity10radon (Python), gocyclo (Go)
Cognitive complexity15ruff C901 (Python)
Function length40 linesPer-language

Fix: Extract helper functions, reduce nesting, simplify conditionals.

Gate 8: Duplication (<5%)

Detects copy-paste code that should be refactored.

  • Tool: jscpd (language-agnostic)
  • Min detection: 5 lines / 50 tokens
  • Threshold: 5% of codebase

Fix: Extract shared logic into functions or modules. Do not create premature abstractions for ❤️ occurrences.

Gate 9: Dependencies

Scans for known vulnerabilities in project dependencies.

LanguageToolScope
Pythonpip-auditPyPI vulnerability database
Nodenpm auditnpm advisory database
GogovulncheckGo vulnerability database
Rustcargo-auditRustSec advisory database

Fix: Update vulnerable dependencies. Pin versions if update breaks compatibility.

Configuration

quality-gate.yml

Place in project root to override defaults:

yaml
thresholds:
  coverage: 80
  cyclomatic_complexity: 10
  cognitive_complexity: 15
  max_function_lines: 40
  duplication_pct: 5
  timeout_per_gate: 60

Environment Variables

VariableDefaultDescription
QUALITY_GATE_CONFIG./quality-gate.ymlConfig file path
QUALITY_GATE_FAIL_FASTfalseStop on first failure
QUALITY_GATE_VERBOSEfalseShow PASS gates
QUALITY_GATE_ALL_FILESfalseCheck all files, not just changed
PROJECT_DIRGit rootProject root directory

Usage

bash
# Run all gates (changed files only)
./scripts/quality/quality-gate.sh

# Run all gates on all files
QUALITY_GATE_ALL_FILES=true ./scripts/quality/quality-gate.sh

# Fail fast on first gate failure
QUALITY_GATE_FAIL_FAST=true ./scripts/quality/quality-gate.sh

# Verbose output
QUALITY_GATE_VERBOSE=true ./scripts/quality/quality-gate.sh

Integration

Taskfile

yaml
tasks:
  quality:
    desc: Run 9-gate quality system
    cmds:
      - ./scripts/quality/quality-gate.sh
  quality:all:
    desc: Run 9-gate quality system on all files
    env:
      QUALITY_GATE_ALL_FILES: "true"
    cmds:
      - ./scripts/quality/quality-gate.sh

Pre-push Hook

bash
#!/bin/bash
./scripts/quality/quality-gate.sh || exit 1

CI Pipeline

yaml
quality-gate:
  script:
    - QUALITY_GATE_ALL_FILES=true ./scripts/quality/quality-gate.sh