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 ruleP2universalStack: universal
namingapi-designsemanticsdefaults
Name optional filter flags so undefined means the intended default
Choose the polarity of an optional filter so that omitting it (undefined) yields the desired default; 'fieldsToPush=undefined' reads as 'push nothing', whereas 'fieldsToExclude=undefined' correctly reads as 'include all'.
PR: hegnar-journalist-boost · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | function build(payload, fieldsToPush) { |
| 2 | // undefined here semantically means 'push nothing', but we treat it as 'push all' |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | function build(payload, fieldsToExclude = []) { |
| 2 | // undefined/[] correctly means 'exclude nothing -> include all' |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)