docs: document the cognitive complexity gate

complexity:check was missing from the list of commands CI runs, so the first
external contributor to trip it hit a failure with no way to have seen it
coming, on a rule the docs never stated.

Says what the number measures and why nesting is what it punishes, so the fix
reads as extracting a helper rather than raising the threshold.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-08-11 08:47:57 -05:00
1 parent b08ecb66cc
commit 1bb82491bd
1 file changed
+2
+2
View File
@@ -108,9 +108,11 @@ npm run lint
npm run format:check
npm run typecheck # must be clean — this includes the compile-time-guarantee type test
npm test # all tests must pass
npm run complexity:check
```
- Write tests for new behavior (TDD welcome). We use Vitest.
- `complexity:check` caps the cognitive complexity of every function in `src/`. What it measures is how much you have to hold in your head to follow a function from top to bottom, and it charges nesting more heavily than branching: a condition inside a closure inside a function costs several times what the same condition costs at the top level. Going over the threshold is not a verdict on your code — it means one function has grown to ask too much of whoever reads it next. The fix is nearly always to lift a nested closure out to module scope, where its branches are charged once instead of three times over. Raising `COMPLEXITY_MAX` is not the fix, even though the script suggests it.
- Keep runtime dependencies at zero beyond `reflect-metadata`.
- A new option or method on a public interface has to change that interface too. An implementation that grows a parameter without `src/app/types.ts` growing it as well is unreachable for anyone consuming the package.
- New public API needs a doc note in `README.md`.