home / skills / amnadtaowsoam / cerebraskills / lint-test-typecheck-policy

This skill enforces code quality in CI by linting, testing, and type checking to prevent defects and ensure consistent software.

npx playbooks add skill amnadtaowsoam/cerebraskills --skill lint-test-typecheck-policy

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.4 KB
---
name: Lint, Test, Typecheck Policy
description: Policy for enforcing code quality through linting, testing, and type checking in CI pipeline
---

# Lint, Test, Typecheck Policy

## Overview

Policy for enforcing code quality standards through automated checks: linting, testing, type checking - must pass everything before merge

## Why This Matters

- **Quality**: Catch bugs before reaching production
- **Consistency**: Code style is the same across the team
- **Safety**: Type errors are caught at compile time
- **Automated**: No need to rely on manual review

---

## Three Pillars

### 1. Lint (Code Style)
```bash
# Must pass
npm run lint

# Zero errors, zero warnings
✓ 0 errors
✓ 0 warnings
```

### 2. Test (Correctness)
```bash
# Must pass
npm test

# All tests pass, coverage ≥80%
✓ 150 tests passing
✓ Coverage: 85%
```

### 3. Typecheck (Type Safety)
```bash
# Must pass
npm run typecheck

# Zero type errors
✓ 0 errors
```

---

## CI Pipeline

```yaml
# .github/workflows/quality-gates.yml
name: Quality Gates
on: [pull_request]

jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
      
      - name: Install
        run: npm ci
      
      - name: Lint
        run: npm run lint
        # Fails on any error/warning
      
      - name: Type Check
        run: npm run typecheck
        # Fails on any type error
      
      - name: Test
        run: npm test -- --coverage
        # Fails if coverage < 80%
      
      - name: Upload Coverage
        uses: codecov/codecov-action@v3
```

---

## Lint Configuration

### ESLint
```javascript
// .eslintrc.js
module.exports = {
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
  ],
  rules: {
    // Errors (must fix)
    'no-console': 'error',
    'no-debugger': 'error',
    '@typescript-eslint/no-explicit-any': 'error',
    '@typescript-eslint/no-unused-vars': 'error',
    
    // Warnings (should fix)
    'complexity': ['warn', 10],
    'max-lines': ['warn', 300],
  }
};
```

### Prettier
```json
{
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5"
}
```

---

## Test Policy

### Coverage Requirements
```json
{
  "jest": {
    "coverageThreshold": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": 80
      }
    }
  }
}
```

### Test Types Required
```
✓ Unit tests (all functions)
✓ Integration tests (critical paths)
✓ E2E tests (user flows)
```

---

## TypeScript Configuration

```json
{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true
  }
}
```

---

## Pre-commit Hooks

```json
{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.ts": [
      "eslint --fix",
      "prettier --write",
      "npm run typecheck"
    ],
    "*.test.ts": [
      "npm test -- --findRelatedTests"
    ]
  }
}
```

---

## Summary

**Quality Gates:** Lint + Test + Typecheck must all pass

**Requirements:**
- Lint: 0 errors, 0 warnings
- Test: All pass, ≥80% coverage
- Typecheck: 0 type errors

**Enforcement:**
- CI pipeline (blocks merge)
- Pre-commit hooks (local)
- Code review (manual check)

**No exceptions:** Must pass everything

Overview

This skill enforces code quality by running linting, testing, and type checking as mandatory gates in CI and locally. It requires zero lint errors/warnings, all tests passing with at least 80% coverage, and zero type errors before a merge is allowed. Pre-commit hooks and CI workflows ensure checks run consistently. No exceptions are permitted.

How this skill works

The policy wires three automated checks into the developer workflow: linting (ESLint + Prettier), testing (Jest with coverage thresholds), and type checking (TypeScript compiler). CI blocks merges on any failure and uploads coverage artifacts. Pre-commit hooks run quick fixes and related tests to catch issues before push.

When to use it

  • Every pull request targeting mainline branches
  • During feature development to maintain consistent style and safety
  • Before any release or deployment pipeline
  • When onboarding new contributors to ensure standards are followed

Best practices

  • Fail fast in CI: stop the pipeline on the first failing quality gate to save resources
  • Enforce zero lint errors and zero warnings to maintain consistent style
  • Require global coverage thresholds (≥80%) and prioritize unit tests for core logic
  • Enable strict TypeScript compiler options (strict, noImplicitAny, strictNullChecks)
  • Run lint --fix and Prettier in pre-commit hooks to reduce friction for contributors

Example use cases

  • Blocking a pull request that introduces a console.log or unused variable via ESLint rules
  • Catching a type regression where a function signature no longer matches callers during typecheck
  • Preventing a merge when coverage drops below 80% by failing the Jest coverage threshold
  • Running lint-staged and typecheck locally as a pre-commit step so CI failures are rare
  • Using the CI workflow to upload coverage reports to Codecov for visibility

FAQ

What happens if CI fails one of the gates?

The pull request is blocked from merging until the failing check is fixed and all gates pass.

Can warnings be allowed temporarily?

This policy requires zero errors and zero warnings; allowlisting warnings is discouraged and must be handled outside this policy.