|
| 1 | +# Coding Standards |
| 2 | + |
| 3 | +These standards guide everyday code contributions. They complement the Security Checklist in the PR template. |
| 4 | + |
| 5 | +## 1) Imports, Exports, and Module Boundaries |
| 6 | + |
| 7 | +- Use **named exports only**; avoid default exports. |
| 8 | +- Use **named imports only**; do not rename imports with `as`. |
| 9 | +- Avoid circular dependencies; keep module boundaries clear. |
| 10 | + |
| 11 | +## 2) TypeScript: Type Safety & Validation |
| 12 | + |
| 13 | +- Avoid `any`, type assertions/casts (`as`, `<Type>`) and the non-null `!` operator unless absolutely necessary and justified. |
| 14 | +- Prefer type guards for safe narrowing. |
| 15 | +- Validate external data (user input, API responses, storage) before use; handle unexpected shapes. |
| 16 | + |
| 17 | +## 3) Naming, Documentation, and Readability |
| 18 | + |
| 19 | +- Use descriptive names; avoid vague terms/abbreviations. |
| 20 | +- Add JSDoc-style comments for methods (purpose, parameters, returns). |
| 21 | +- Prefer one statement per line (including split chained calls). |
| 22 | +- Prefer modern TS/JS features (destructuring, spread/rest). |
| 23 | + |
| 24 | +## 4) Coding Style & Functionality |
| 25 | + |
| 26 | +- Minimize variable scope; declare variables near first use. |
| 27 | +- Prefer early returns over deep nesting. |
| 28 | +- Keep helper functions pure and side-effect free. |
| 29 | +- Prefer arrow functions unless `this/arguments` semantics are required. |
| 30 | +- Ensure no unhandled promises. |
| 31 | + |
| 32 | +## 5) React: Effects, State, and Components |
| 33 | + |
| 34 | +- Do **not** reach for `useEffect` by default; trigger actions from events. |
| 35 | +- Use declarative data tools instead of hand-wired effects where possible. |
| 36 | +- Each effect has a single responsibility with minimal, stable deps. |
| 37 | +- Avoid inline objects/functions that cause re-renders. |
| 38 | +- Keep components βdumbβ and focusedβrender from props; move logic up. |
| 39 | +- Prefer functional components + hooks. |
| 40 | +- Use stable keys in lists (never array indexes). |
| 41 | + |
| 42 | +## 6) Abstraction and Duplication |
| 43 | + |
| 44 | +- Duplication is sometimes better than a wrong abstraction. |
| 45 | +- Inline first; abstract once patterns stabilize. |
| 46 | +- Be willing to delete/inline poor abstractions. |
| 47 | + |
| 48 | +## 7) Accessibility (a11y) |
| 49 | + |
| 50 | +- Full keyboard support; visible focus; Escape closes modals. |
| 51 | +- Use appropriate ARIA landmarks/roles; live regions for async updates. |
| 52 | +- Custom components follow accessible patterns (e.g., focus-trapped dialogs, proper labeling, sensible tab order). |
| 53 | + |
| 54 | +## 8) Testing |
| 55 | + |
| 56 | +- Component unit tests for new/changed logic (cover success & failure paths). |
| 57 | +- E2E tests for affected critical paths, or mark N/A with a reason. |
| 58 | +- For TS modules, include meaningful unit tests; emphasize public APIs; prefer pure functions. |
| 59 | + |
| 60 | +## 9) Technology Choices ([Tech Radar](./tech-radar.md)) |
| 61 | + |
| 62 | +- Use well-understood, approved technologies. |
| 63 | +- If introducing experimental tech, keep usage limited, justify it. |
| 64 | +- Do not introduce unrecommended tech; prefer refactoring/migrating away. |
| 65 | + |
| 66 | +## 10) Documentation |
| 67 | + |
| 68 | +- Update documentation when behavior or usage changes. |
| 69 | +- Document migrations. |
| 70 | +- Keep PR title/description clear and consistent with the change. |
| 71 | +- Link the PR to the relevant Jira ticket. |
| 72 | + |
| 73 | +## 11) PR Formatting & Media |
| 74 | + |
| 75 | +- For UI/design changes, include screenshots or a short video. |
| 76 | +- For technical PRs, include a clear description of the problem, scope, and user impact. |
| 77 | +- Add inline comments on critical paths/logic to guide reviewers. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +**Note:** Security-critical checks live in the PR templateβs βSecurity Checklistβ and must be explicitly acknowledged there. |
0 commit comments