|
| 1 | +--- |
| 2 | +description: |
| 3 | +globs: |
| 4 | +alwaysApply: true |
| 5 | +--- |
| 6 | + |
| 7 | +Coding style: |
| 8 | + |
| 9 | +- Favor `async run() {` over `run = async () => {` inside ES6 classes |
| 10 | +- Favor `if (!(err instanceof Error)) { throw new Error(`Was thrown a non-error: ${err}`) }` inside |
| 11 | + `catch` blocks to ensure the `error` is always an instance of `Error` |
| 12 | +- Favor using real paths (`../lib/schemas.ts`) over aliases (`@/app/lib/schemas`). |
| 13 | +- Favor `for (const comment of comments) {` over `comments.forEach((comment) => {` |
| 14 | +- Favor named exports over default exports, with the exception of Next.js pages |
| 15 | +- Do not wrap each function body and function call in `try`/`catch` blocks. It pollutes the code. |
| 16 | + Assume we will always have an e.g. |
| 17 | + `main().catch((err) => { console.error(err); process.exit(1) })` to catch us. I repeat: Avoid |
| 18 | + over-use of try-catch such as |
| 19 | + `try { // foo } catch (err) { console.error('error while foo'); throw err }`, assume we catch |
| 20 | + errors on a higher level and do not need the extra explananation. |
| 21 | +- If you must use try/catch, for simple cases, favor `alphalib/tryCatch.ts` |
| 22 | + (`const [err, data] = await tryCatch(promise)`) over |
| 23 | + `let data; try { data = await promise } catch (err) { }` |
| 24 | +- Before creating new files and new code, see if we can leverage existing work, maybe slighty adapt |
| 25 | + that without breaking BC, to keep things DRY. |
| 26 | +- Favor early exits, so quickly `continue`, `return false` (or `throw` if needed), over nesting |
| 27 | + everything in positive conditions, creating christmas trees. |
| 28 | +- Use Prettier with 100 char line width, single quotes for JS/TS, semi: false |
| 29 | +- Use descriptive names: PascalCase for components/types, camelCase for variables/methods/schemas |
| 30 | +- Alphabetize imports, group by source type (built-in/external/internal) |
| 31 | +- Favor US English over UK English, so `summarizeError` over `summarise Error` |
| 32 | +- Favor `.replaceAll('a', 'b)` over `.replace(/a/g, 'b')` or `.replace(new RegExp('a', 'g'), 'b')` when the only need for regeses was replacing all strings. That's usually both easier to read and more performant. |
| 33 | +- Use typographic characters: ellipsis (`…`) instead of `...`, curly quotes (`'` `"`) instead of straight quotes in user-facing text |
| 34 | +- Put API keys and secrets in `.env` files, not hardcoded in components |
| 35 | +- Check for existing hooks before creating new ones (e.g., `useUppy()` for Uppy functionality) |
0 commit comments