Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP1universalStack: TypeScript
namingside-effectssingle-responsibilityclean-code
Name a method for what it actually does, including side effects
A method named as a pure query (e.g. evaluate/get) must not also mutate state; either split read and write or rename it to reflect the mutation.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | // 'evaluate' implies read-only, but it also writes a cookie |
| 2 | public static evaluatePopupState(): PopupState { |
| 3 | const cookie = getCookie(name); |
| 4 | if (cookie.showPopup) { |
| 5 | setCookie(name, JSON.stringify({ ...cookie, showPopup: false })); // mutation! |
| 6 | } |
| 7 | return { showOnInitialLoad: cookie.showPopup }; |
| 8 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | public static getPopupState(): PopupState { |
| 2 | const cookie = getCookie(name); |
| 3 | return { showOnInitialLoad: cookie.showPopup }; |
| 4 | } |
| 5 |
|
| 6 | public static markPopupShown(): void { |
| 7 | setCookie(name, JSON.stringify({ ...getCookie(name), showPopup: false })); |
| 8 | } |
Explanation (EN)
Objašnjenje (HR)