utils/ts_config/.pre-commit-config.yaml
Krzysztof kuhy Rudnicki 128ede438e ts_config: @kuhyx/ts-config, the one lint/TS bar every TypeScript repo extends
Evil Martians' "ten anti-AI-slop moves" as a package: strict tsconfig base
(noUncheckedIndexedAccess, exactOptionalPropertyTypes), type-checked
typescript-eslint strict+stylistic, unicorn/sonarjs/perfectionist, behaviour
rules for tests (expect-expect, no-focused-tests), React (hooks, @eslint-react,
jsx-a11y strict, you-might-not-need-an-effect), Playwright, and layer
boundaries via eslint-plugin-boundaries 7 with the article's default policies.
Knip / jscpd / Stryker bases; Stryker carries no break threshold on purpose.

Plugins are dependencies, not devDependencies: a flat config imports them from
this package's own node_modules, so a consumer installing from the git tag
gets them or the lint cannot run. No build step, so the tag needs no prepare.

test/fixture is a mini repo with one planted violation per rule family;
test/expected.js names the rule that must catch each, and the suite runs the
real CLI over it (in a child process -- v8 coverage merges natively-loaded
and transformed copies of the same module into "uncovered"). 35 tests, 100%
branch coverage on the factories.

eslint/fast.js is the type-free subset for a per-edit hook: 0.52 s cold on
one file, measured against 1.28 s for base() without types -- importing a
plugin is the cost, so it loads none, nor base.js which imports them.

Probed under ESLint 10: jsx-a11y 6.10.2 (peer says <=9) and boundaries 7.2.0
both run; the fixture pins that.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnAYyNH1Sm4iJNidfYbrZJ
2026-09-16 21:40:08 +02:00

55 lines
1.9 KiB
YAML

# Pre-commit Configuration for ts_config
# Install: pre-commit install && pre-commit install --hook-type pre-push
# Run: pre-commit run --config ts_config/.pre-commit-config.yaml --all-files
# NOTE: this subproject lives inside the ~/src/utils monorepo, whose git root is
# one level up. pre-commit always runs hooks from the git root, so every path
# below is written relative to THAT, not to this directory, and the top-level
# `files` key keeps these hooks off the sibling subprojects. Mirrors
# web_ui/.pre-commit-config.yaml.
files: ^ts_config/
# The fixture exists to violate every rule; formatting hooks must not "fix" it.
exclude: ^ts_config/test/fixture/
default_stages: [pre-commit]
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: check-yaml
# pnpm 12 writes the lockfile as two YAML documents.
args: [--allow-multiple-documents]
- id: check-json
# tsconfig*.json are JSONC -- TypeScript allows comments.
exclude: ^ts_config/tsconfig.*\.json$
- id: check-merge-conflict
- id: mixed-line-ending
args: [--fix=lf]
- repo: local
hooks:
- id: file-length-cap
name: file length <= 250 lines
entry: bash scripts/check_file_length.sh
language: system
pass_filenames: true
- id: ts-config-lint
name: ts_config eslint (the preset lints itself)
entry: bash -c 'cd ts_config && pnpm lint'
language: system
pass_filenames: false
files: ^ts_config/.*\.(js|mjs|json)$
- id: ts-config-test
name: ts_config fixture + factory tests, 100% coverage
entry: bash -c 'cd ts_config && pnpm coverage'
language: system
pass_filenames: false
stages: [pre-push]