@shaulavo/standards 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaulavo/standards",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Shared code-quality gates, CI, project template and engineering skills",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -12,14 +12,17 @@
12
12
  },
13
13
  "files": [
14
14
  "dist",
15
- "config"
15
+ "config",
16
+ "skills",
17
+ ".claude-plugin"
16
18
  ],
17
19
  "type": "module",
18
20
  "scripts": {
19
21
  "build": "bun build src/cli.ts src/knip-reporter.ts src/react-compiler-plugin.ts --target node --format esm --external oxc-parser --external oxc-plugin-react-compiler --outdir dist",
20
22
  "prepack": "bun run build",
21
23
  "test": "bun test ./tests",
22
- "check": "bun run build && node dist/cli.js oxfmt --check && node dist/cli.js oxlint && node dist/cli.js suppressions && node dist/cli.js source --allow tests/fixtures/ && node dist/cli.js dupes && node dist/cli.js structure && node dist/cli.js actionlint && node dist/cli.js knip && node dist/cli.js tsc && node dist/cli.js doctor && bun test ./tests"
24
+ "size": "bun run scripts/size.ts",
25
+ "check": "bun run build && node dist/cli.js oxfmt --check && node dist/cli.js oxlint && node dist/cli.js suppressions && node dist/cli.js source --allow tests/fixtures/ && node dist/cli.js dupes && node dist/cli.js structure && node dist/cli.js actionlint && node dist/cli.js knip && node dist/cli.js tsc && node dist/cli.js skills validate && node dist/cli.js doctor && bun run size && bun test ./tests"
23
26
  },
24
27
  "dependencies": {
25
28
  "@tsconfig/bun": "1.0.12",
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: design-doc
3
+ description: Write a concise architectural design document before any major feature, refactor, backend swap, or architecture change. Covers existing code, explicit threat model and non-goals, off-the-shelf-first evaluation, prior art, ownership boundaries, deletions, PR slices, and verification gates. Pairs with the architect skill for code-level shape exploration.
4
+ license: MIT
5
+ ---
6
+
7
+ # Design doc
8
+
9
+ Write a short architectural design document before implementing a major feature, refactor, backend swap, or cross-cutting architecture change. Sketch two alternative code-level shapes directly (or optionally pair with the **architect** skill on Cursor) for types, signatures, and module boundaries, and use this skill for the surrounding architectural contract.
10
+
11
+ ## Required sections
12
+
13
+ Keep each section concrete and grounded in real files, commands, and measurements. Never prose-compile internal helper functions or struct layouts that belong in code and tests.
14
+
15
+ 1. **Existing code.** Read the current implementation first and cite exact files and responsibilities. Do not design features on top of a broken subsystem slated for replacement; simplify or replace the foundation first.
16
+ 2. **Threat model and non-goals.** List the concrete failure modes the design defends against, then state explicit **Non-goals**. Reviewers may not demand machinery for failures placed out of scope.
17
+ 3. **Off-the-shelf first and prior art.** Default to off-the-shelf libraries, tools, and containers for everything non-core. Build from scratch only for a product's core differentiator or with concrete proof why no existing library fits. Survey at least two existing open-source projects that solved a similar problem and state what you borrow and what you deliberately do differently.
18
+ 4. **Ownership boundaries and data model.** Name one owner per piece of state, config, or version pin. Avoid blind drop-in swaps and duplicate parallel pipelines.
19
+ 5. **Deletions and cutover symmetry.** List every file, script, flag, and compatibility branch the change deletes. Verify both halves of each cutover so no writer lacks a reader, no reader lacks a writer, and every deleted invariant moves into an automated check before deletion.
20
+ 6. **PR slices and verification gates.** Split delivery into small, independently verifiable pull requests. For each slice, state the exact tests, negative controls, or before/after measurements that prove it done.
21
+
22
+ ## Guardrails
23
+
24
+ - Skip a full design document for local bug fixes or changes contained within one or two files; sketch the shape directly (or use **architect** on Cursor) and implement.
25
+ - Separate reproduced facts (commands and outputs already run) from open questions (hypotheses still needing a probe, each assigned to the slice that proves it).
26
+ - Keep public design docs focused on code, architecture, and verification. Leave out internal workflow chatter or private repository names when the document is public.
@@ -0,0 +1,124 @@
1
+ ---
2
+ name: never-nester
3
+ description: Keep nesting depth at three levels or fewer, ban nested ternaries and else after early return, and apply clean TypeScript array construction idioms that linters cannot enforce. Use when writing, reviewing, or refactoring TypeScript or JavaScript code.
4
+ license: MIT
5
+ ---
6
+
7
+ # Never nester
8
+
9
+ Limit every function to a maximum nesting depth of 3, never write nested ternaries, and never write `else` after an early return.
10
+
11
+ Every block-opening construct (`if`, `else`, `for`, `while`, `try`, `switch`, arrow function body, callback body) adds one depth level. A function body is depth 1, an `if` inside it is depth 2, and a loop inside that is depth 3. Never go to depth 4.
12
+
13
+ Note: Oxlint's `max-depth: 2` enforces this for statements inside one function, but restarts its count inside nested callbacks and arrow functions. Enforce depth across nested callbacks during authoring and review.
14
+
15
+ ## Two denesting techniques
16
+
17
+ ### 1. Inversion (early return)
18
+
19
+ Flip failure conditions into guard clauses at the top of a function so the happy path runs at depth 1. Inside loops, invert conditions to `continue`.
20
+
21
+ Before (depth 4):
22
+
23
+ ```ts
24
+ function processUser(user: User | null): Result | null {
25
+ if (user) {
26
+ if (user.isActive) {
27
+ if (user.hasPermission) {
28
+ return doWork(user)
29
+ }
30
+ }
31
+ }
32
+ return null
33
+ }
34
+ ```
35
+
36
+ After (depth 2):
37
+
38
+ ```ts
39
+ function processUser(user: User | null): Result | null {
40
+ if (!user) return null
41
+ if (!user.isActive) return null
42
+ if (!user.hasPermission) return null
43
+ return doWork(user)
44
+ }
45
+ ```
46
+
47
+ Loop inversion:
48
+
49
+ ```ts
50
+ for (const item of items) {
51
+ if (!item.isActive) continue
52
+ if (item.value <= threshold) continue
53
+ results.push(transform(item))
54
+ }
55
+ ```
56
+
57
+ ### 2. Extraction (pull into a helper)
58
+
59
+ When inversion still leaves depth 4, extract the inner block into a named function with one clear responsibility.
60
+
61
+ Before (depth 4):
62
+
63
+ ```ts
64
+ function processAll(items: readonly Item[]): void {
65
+ for (const item of items) {
66
+ if (item.isValid) {
67
+ for (const part of item.parts) {
68
+ handle(part)
69
+ }
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ After (depth 2 each):
76
+
77
+ ```ts
78
+ function processAll(items: readonly Item[]): void {
79
+ for (const item of items) {
80
+ processItem(item)
81
+ }
82
+ }
83
+
84
+ function processItem(item: Item): void {
85
+ if (!item.isValid) return
86
+ for (const part of item.parts) {
87
+ handle(part)
88
+ }
89
+ }
90
+ ```
91
+
92
+ ## Control-flow rules
93
+
94
+ 1. **Max depth 3.** Count every block-opening construct, including nested callbacks.
95
+ 2. **Invert first, extract second.** Flatten guards with `return` or `continue` before creating new helper functions.
96
+ 3. **Group guard clauses at the top.** Keep validation guards together, followed by the main path.
97
+ 4. **No `else` after an early return.** The branch after `return`, `throw`, or `continue` is already flat.
98
+ 5. **No nested ternaries.** `a ? b : c ? d : e` is forbidden. Replace it with a small helper with early returns, a `switch`, or a lookup record. A single flat ternary (`cond ? a : b`) is fine.
99
+
100
+ ```ts
101
+ function statusLabel(status: Status): string {
102
+ if (status === 'done') return 'Done'
103
+ if (status === 'error') return 'Failed'
104
+ return 'Running'
105
+ }
106
+ ```
107
+
108
+ ## Array construction idioms
109
+
110
+ Apply these alongside the **typescript-best-practices** skill for patterns static lint rules do not catch:
111
+
112
+ - **Combine arrays with `concat`.** Write `first.concat(second, third)` instead of multi-spread array literals. Group literal items into array arguments when appending or prepending.
113
+ - **Map iterables in one pass.** Prefer `Array.from(iterable, mapper)` over `[...iterable].map(mapper)` or `Array.from(iterable).map(mapper)`. Take a snapshot first only when `mapper` can mutate or reenter `iterable`.
114
+ - **Sort or reverse without unnecessary copies.** Sort or reverse owned arrays in place when their prior order is no longer needed. Use `toSorted` or `toReversed` on borrowed ordinary arrays instead of `[...items].sort()` or `Array.from(items).reverse()`.
115
+ - **Use fresh array results directly.** `map`, `filter`, `flatMap`, `slice`, `concat`, `Array.from`, and `toSorted` already allocate a new array. Do not wrap them in `[...items.map(fn)]` or another spread.
116
+ - **Copy only for ownership or representation.** Copying a borrowed array before mutating it, or converting a `Set`, iterator, DOM collection, or typed array to an ordinary array, is valid when required. Preserve tuple types, sparse-array behavior, and evaluation order.
117
+ - **Widen internal read-only parameters to `readonly`.** Do not copy an array at a call site just to satisfy a mutable parameter type. Type heterogeneous `concat` results on the destination variable instead of adding casts or extra copies.
118
+ - **Document performance exceptions.** If a hot path justifies breaking one of these idioms, include a measurement and a brief comment at the call site.
119
+
120
+ ```ts
121
+ const merged: Entry[] = first.concat(second, third)
122
+ const names = entries.map((entry) => entry.name)
123
+ const mapped = Array.from(idSet, (id) => id.trim())
124
+ ```