Skip to content

Commit 5b4c111

Browse files
authored
chore(ratchet): require ci-ratchet; add scripts/hooks/CI, baseline; README/CLI next steps
require ci-ratchet status check; add scripts/hooks/CI; add baseline; update README and DEVELOPING; CLI init prints ratchet next steps
1 parent 084f08f commit 5b4c111

File tree

8 files changed

+1119
-2
lines changed

8 files changed

+1119
-2
lines changed

.github/workflows/ci-ratchet.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: ci-ratchet
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
ratchet-and-tests:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: '20'
17+
cache: 'npm'
18+
19+
- name: Install dependencies
20+
run: npm ci
21+
22+
- name: ESLint JSON
23+
run: npm run lint:json
24+
25+
- name: Analyze current
26+
run: npm run analyze:current
27+
28+
- name: Ratchet (fail on new debt)
29+
run: npm run ratchet
30+
31+
- name: Run tests
32+
run: npm test
33+
34+
- name: Upload artifacts
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: analysis-and-lint-${{ github.sha }}
38+
path: |
39+
lint-results.json
40+
analysis-current.json
41+
if-no-files-found: error
42+
retention-days: 7

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npm test
1+
npm run lint:json && npm run analyze:current && npm run ratchet && npm test

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ ESLint plugin with AI agent configuration generator for JavaScript projects.
1010

1111
## What This Provides
1212

13-
This plugin combines two functions:
13+
This plugin combines two functions and built-in guardrails:
1414

1515
1. **ESLint rules** - 8 rules targeting AI-generated code patterns
1616
2. **Configuration generator** - CLI tool that creates AI agent guides and ESLint configs
17+
3. **Guardrails: No-New-Debt Ratchet** — hooks + CI that block increases in analyzer categories. See [No-New-Debt Ratchet (All projects)](#no-new-debt-ratchet-all-projects)
1718

1819
### Generated Files
1920

@@ -87,6 +88,7 @@ After setup, you'll have:
8788

8889
- Review `AGENTS.md` for coding guidelines
8990
- Run `npx eslint .` to check your code
91+
- Enable the No‑New‑Debt Ratchet to prevent regressions (see section below)
9092
- Use AI assistants (they'll automatically read AGENTS.md)
9193

9294
## Quick Start
@@ -464,6 +466,48 @@ This tool is designed for JavaScript/Node.js projects and is currently in active
464466

465467
---
466468

469+
## No-New-Debt Ratchet (All projects)
470+
471+
Keep quality trending in one direction only: better. The ratchet blocks any increase in analyzer categories (complexity, architecture, domain terms, magic numbers) while allowing gradual cleanup.
472+
473+
Why this matters (works for greenfield and brownfield)
474+
- New templates often ship with violations; accept the baseline once, then prevent regressions
475+
- Rapid prototyping: iterate fast without blocking, but never get worse than the last accepted state
476+
- AI-generated and copied code: capture current count as baseline; fix over time
477+
478+
How it works in this repo
479+
- Baseline file: analysis-baseline.json
480+
- Local hook: pre-push runs `npm run lint:json && npm run analyze:current && npm run ratchet && npm test`
481+
- CI: .github/workflows/ci-ratchet.yml runs the same and uploads artifacts
482+
483+
Usage
484+
```bash
485+
# Create/refresh baseline from current state (intend to accept current count)
486+
npm run lint:json && npm run analyze:baseline
487+
488+
# Check current branch against baseline (runs in hooks/CI)
489+
npm run lint:json && npm run analyze:current && npm run ratchet
490+
491+
# After reducing violations, refresh baseline intentionally
492+
npm run lint:json && npm run analyze:baseline
493+
# Commit the updated baseline (recommended message):
494+
# 'ratchet: refresh baseline after reductions'
495+
```
496+
497+
Modes for different project types
498+
- Zero-Tolerance (pure greenfield)
499+
- Keep baseline at 0; optionally promote key rules to error in CI-only config
500+
- Flexible Greenfield (prototype mode)
501+
- Set baseline from current state (e.g., template/prototype); prevent increases; ratchet down as you fix
502+
- Brownfield (existing code)
503+
- Set baseline from current codebase; prevent increases; reduce over time; optionally use path-specific overrides for legacy areas
504+
505+
Adopting ratchet in other repos
506+
- Manual setup today: copy scripts/ratchet.js, add the npm scripts shown above, wire a pre-push hook, and add a CI job similar to ci-ratchet
507+
- Coming soon: a one-shot "guardrails setup" command to scaffold these pieces automatically (see issue #180)
508+
509+
---
510+
467511
## Developing (Self-hosting guardrails)
468512

469513
For contributors to this repo (self-hosting the plugin): running our rule fixers on the plugin’s own rule sources can mutate rule implementations. We added guardrails and documented a safe workflow — see docs/DEVELOPING.md.

0 commit comments

Comments
 (0)