|
| 1 | +# Copilot Instructions |
| 2 | + |
| 3 | +## Philosophy |
| 4 | + |
| 5 | +- **Pure Functions**: Favor pure functions (no side effects, no mutation, deterministic) as advocated by Eric Elliott. |
| 6 | +- **Test-Driven Development (TDD)**: Write tests first, code in small, testable increments, following Uncle Bob’s TDD cycle. |
| 7 | +- **Extreme Programming (XP)**: Embrace simplicity, communication, feedback, and courage. Prefer small, frequent, high-quality changes. |
| 8 | +- **Framework Agnostic**: Do not use any frameworks or libraries unless explicitly requested. Use only standard JavaScript (ESM). |
| 9 | +- **JSDoc**: All functions, classes, and modules must be documented with JSDoc for type safety and clarity. |
| 10 | +- **Design Patterns**: Use classic, well-known patterns (factory, strategy, observer, etc.) only when they add clarity or testability. |
| 11 | +- **Clean Code**: Prioritize readability, maintainability, and simplicity. Avoid cleverness for its own sake. |
| 12 | +- **Testability**: All code should be easily testable. Avoid hidden dependencies and global state. |
| 13 | +- **Small Iterations**: Make small, incremental changes. Each change should be easy to review and test. |
| 14 | +- **No Frameworks**: Do not use React, Vue, Angular, or any other framework. No build tools unless explicitly requested. |
| 15 | + |
| 16 | +## Coding Guidelines |
| 17 | + |
| 18 | +- Use **ES Modules** (`import`/`export`). |
| 19 | +- Use **pure functions** wherever possible. |
| 20 | +- Use **const** and **let** (never `var`). |
| 21 | +- Use **arrow functions** for short, stateless functions. |
| 22 | +- Use **descriptive names** for variables, functions, and classes. |
| 23 | +- **No mutation** of input arguments. |
| 24 | +- **No side effects** in pure functions. |
| 25 | +- **No global state** unless absolutely necessary (and then, document it). |
| 26 | +- **JSDoc** for every function, class, and exported symbol. |
| 27 | +- **Write a test** for every new function or feature (see `/src/*.test.js` for examples). |
| 28 | +- **Keep files small** and focused on a single responsibility. |
| 29 | +- **No magic numbers**—use named constants. |
| 30 | +- **No unnecessary abstractions**—keep it simple. |
| 31 | + |
| 32 | +## Example Function |
| 33 | + |
| 34 | +```js |
| 35 | +/** |
| 36 | + * Adds two numbers (pure function). |
| 37 | + * @param {number} a |
| 38 | + * @param {number} b |
| 39 | + * @returns {number} |
| 40 | + */ |
| 41 | +export const add = (a, b) => a + b |
| 42 | +``` |
| 43 | + |
| 44 | +## Example Test |
| 45 | + |
| 46 | +```js |
| 47 | +import assert from 'node:assert/strict' |
| 48 | +import { add } from './add.js' |
| 49 | + |
| 50 | +assert.equal(add(2, 3), 5) |
| 51 | +``` |
| 52 | + |
| 53 | +## When in Doubt |
| 54 | + |
| 55 | +- **Ask for clarification** if requirements are unclear. |
| 56 | +- **Prefer simplicity** over cleverness. |
| 57 | +- **Write tests** for all edge cases. |
| 58 | +- **Document** all exported symbols with JSDoc. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +**Summary:** |
| 63 | +Write clean, pure, framework-agnostic JavaScript (ESM) with JSDoc and tests. |
| 64 | +Favor small, testable, incremental changes. |
| 65 | +No frameworks, no unnecessary abstractions, no side effects. |
| 66 | + |
| 67 | +--- |
| 68 | + |
0 commit comments