|
| 1 | +--- |
| 2 | +paths: |
| 3 | + - 'packages/**/*.ts' |
| 4 | +--- |
| 5 | + |
| 6 | +# TypeScript Rules |
| 7 | + |
| 8 | +These rules are enforced by OXLint (`.oxlintrc.json`) and must be followed in all code under `packages/`: |
| 9 | + |
| 10 | +## Functional programming |
| 11 | + |
| 12 | +- **No `let`** — use `const` only. No reassignment, no mutation. |
| 13 | +- **No loops** (`for`, `while`, `do...while`, `for...in`, `for...of`) — use `map`, `filter`, `reduce`, `flatMap`, etc. Prefer `es-toolkit` utilities. |
| 14 | +- **No classes** — use plain objects, closures, and factory functions. |
| 15 | +- **No `this`** — never reference `this`. |
| 16 | +- **No `throw`** — no throw statements or throw expressions. Return errors as values. |
| 17 | +- **No IIFEs** — no immediately invoked function expressions. Extract into a named function and call it. |
| 18 | +- **No expression statements** — every expression must be used (assigned, returned, or passed). Config files (`.config.ts`) are exempt. |
| 19 | +- **Immutable data** — no mutating objects or arrays after creation. Config files are exempt. |
| 20 | +- **Prefer tacit (point-free)** — e.g. `arr.filter(isEven)` not `arr.filter((x) => isEven(x))`. |
| 21 | +- **Functional parameters** — functions must declare explicit parameters (no `arguments`, no rest-only patterns). |
| 22 | + |
| 23 | +## TypeScript strictness |
| 24 | + |
| 25 | +- **No `any`** — use `unknown`, generics, or proper types. |
| 26 | +- **No non-null assertions** (`!`) — use explicit null checks. |
| 27 | +- **No optional chaining** (`?.`) — use explicit `if`/`else` or pattern matching. |
| 28 | +- **No ternaries** — use `if`/`else` or `match` expressions. |
| 29 | +- **ESM only** with `verbatimModuleSyntax` — use `import type` for type-only imports. |
| 30 | + |
| 31 | +## General |
| 32 | + |
| 33 | +- **No `eval`**, `new Function()`, or implied eval. |
| 34 | +- **No `var`** — use `const`. |
| 35 | +- **No param reassignment** — parameters are immutable. |
| 36 | +- **No bitwise operators**, `++`/`--`, `void`, `with`, `continue`, or multi-assign. |
| 37 | +- **No circular imports**, self-imports, or duplicate imports. |
| 38 | +- **Prefer `node:` protocol** for Node.js builtins (e.g. `import fs from 'node:fs'`). |
| 39 | +- **Use `es-toolkit`** over hand-rolling utility functions. |
| 40 | + |
| 41 | +## File structure |
| 42 | + |
| 43 | +Every source file follows this order: |
| 44 | +1. **Imports** — node builtins, blank line, external packages, blank line, internal (farthest-to-closest, alphabetical). Top-level `import type`, no inline type specifiers. |
| 45 | +2. **Module-level constants** |
| 46 | +3. **Exported functions** — public API first, each with full JSDoc |
| 47 | +4. **Section separator** (`// ---------------------------------------------------------------------------`) |
| 48 | +5. **Private helpers** — non-exported functions, each with JSDoc including `@private` |
| 49 | + |
| 50 | +## Exports |
| 51 | + |
| 52 | +- **Inline exports only** — use `export` directly on declarations (`export function`, `export interface`, `export const`). Never batch-export local declarations with `export { foo, bar }`. |
| 53 | +- **Re-exports allowed** — barrel/index files may use `export { foo } from './bar.js'` and `export type { Baz } from './baz.js'`. |
| 54 | + |
| 55 | +## JSDoc |
| 56 | + |
| 57 | +- **All functions** require JSDoc — exported and non-exported. |
| 58 | +- **Non-exported functions** must include the `@private` tag. |
| 59 | +- **Test files** are exempt. |
| 60 | + |
| 61 | +## Formatting (OXFmt) |
| 62 | + |
| 63 | +- 100-char line width, 2-space indent, semicolons, single quotes, trailing commas |
| 64 | +- Import sorting: builtin > external > internal > parent/sibling/index |
0 commit comments