From 1bb82491bdcf5eaec96ec226a8ca2fb984a19325 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Tue, 11 Aug 2026 08:47:57 -0500 Subject: [PATCH] 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 --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5fb81fd..5ef4646 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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`.