Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use the nullish-coalescing operator for default/fallback values
Prefer `a ?? b` over verbose conditional fallbacks (and over `||` when 0/'' are valid) for picking an existing value.
Bad example
| 1 | const desc = values.description == null ? entity.description : values.description; |
Explanation (EN)
Verbose fallback logic can be shortened only when the same missing-value cases are handled.
Objašnjenje (HR)
Good example
| 1 | const desc = values.description ?? entity.description; |
Explanation (EN)
Both expressions use the fallback for null and undefined and preserve other values.
Objašnjenje (HR)
Notes (EN)
Use ?? when both null and undefined mean missing and all other values, including zero/false/empty string, must remain.
Exceptions / Tradeoffs (EN)
An undefined-only ternary preserves null; replacing it with ?? changes explicit-null behavior, such as clearing a PATCH field. || is correct when every falsy value should select the fallback.