|
11 | 11 | - Keep notes in `notes/` as markdown files named `dd-mm-yy-topic.md` |
12 | 12 |
|
13 | 13 | ## Coding Conventions |
| 14 | + |
| 15 | +### Naming |
| 16 | +- Never shorten self-documentary names unless the short form is also self-documentary and well-known (e.g. `btn`, `el`, `i` are OK; `ct`, `coll`, `sub` are not) |
| 17 | +- Replace magic numbers with named constants |
| 18 | +- Use pronounceable, searchable names |
| 19 | +- Function names must accurately describe the operation, not the caller's intent |
| 20 | +- Prefer domain-specific terms over generic words (e.g. `node` over `item` when the domain calls them nodes) |
| 21 | +- Avoid encodings — don't append prefixes or type information |
| 22 | + |
| 23 | +### Functions |
| 24 | +- Functions should do one thing |
| 25 | +- Prefer fewer arguments (ideally ≤ 3) |
| 26 | +- Functions should have no side effects — do what the name suggests and nothing else |
| 27 | +- Don't use flag arguments; split into separate functions |
| 28 | + |
| 29 | +### Comments |
| 30 | +- Always try to explain yourself in code first; comment only when code can't be clear enough on its own |
| 31 | +- Don't add obvious/redundant comments |
| 32 | +- Don't comment out code — just remove it (version control exists) |
| 33 | +- Use comments for intent, clarification, or warning of consequences |
| 34 | +- Always use standard comment styles, no extra dashes or decorations |
| 35 | +- In multiline comments, add blank lines between logical points |
| 36 | + |
| 37 | +### Structure |
14 | 38 | - Respect existing indentation style in each file |
15 | 39 | - Keep lines shorter than 80 columns (including comments), but don't break a line just to shave a few characters if it hurts readability |
| 40 | +- Don't break a logical unit of code across lines when it fits on one line |
16 | 41 | - No trailing whitespace |
17 | | -- In multiline comments, add blank lines between logical points |
| 42 | +- Separate concepts vertically with blank lines |
| 43 | +- Related code should appear vertically dense (close together) |
| 44 | +- Declare variables close to their usage |
| 45 | +- Dependent functions should be close to each other |
| 46 | +- Place called functions below their callers (downward direction) |
| 47 | + |
| 48 | +### General |
| 49 | +- Be consistent — if you do something a certain way, do all similar things the same way |
| 50 | +- Avoid negative conditionals (prefer `isActive` over `isInactive`) |
| 51 | +- Encapsulate boundary conditions in one place |
| 52 | +- Don't repeat yourself (DRY), but don't abstract prematurely either |
18 | 53 |
|
19 | 54 | ### JS |
20 | 55 | - Avoid semicolons unless absolutely necessary |
21 | 56 | - Always use curly braces {} for control structures (if, for, while, etc.), even for single statements |
22 | 57 | - For multiline arrow functions without explicit parentheses, always use curly braces with return (e.g., `=> { return ... }`, not `=> expr` spanning lines). Implicit return with parentheses is OK (e.g., `=> ({...})`) |
23 | 58 | - Respect default JSHint rules |
24 | | -- Break logical operator chains (&&, ||) across lines only when significantly long |
| 59 | +- Keep logical operator chains (&&, ||) on one line unless they exceed 80 columns |
25 | 60 | - Keep short destructured imports on one line; break across lines only when exceeding 80 columns |
26 | 61 | - Keep ternary `?` at end of line, not start of next |
27 | 62 | - Always check for unused imports after finishing work on a module |
28 | 63 |
|
29 | 64 | ### CSS |
30 | | -- Order CSS properties from layout-affecting to cosmetic: positioning → display/layout → box model (padding, border) → typography → background/color → decoration (shadow, opacity) → animation → z-index |
| 65 | +- Order CSS properties from layout-affecting to cosmetic: positioning/z-index → display/layout → box model (padding, border) → typography → background/color → decoration (shadow, opacity) → animation |
31 | 66 | - Never use arbitrarily high z-index values; use the lowest value that works |
32 | 67 |
|
33 | 68 | ## Testing |
|
0 commit comments