Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Match a known-position marker with startsWith/endsWith, not includes
When checking for a marker that must sit at a specific position (a prefix or suffix), use startsWith/endsWith rather than includes. includes matches the substring anywhere, which risks false positives when the same characters legitimately appear elsewhere in the value.
Bad example
| 1 | if (path.includes('/admin')) denyPublic(); |
| 2 | // also matches '/blog/adminguide' |
Explanation (EN)
includes fires anywhere in the string, so unrelated values that merely contain the marker also match.
Objašnjenje (HR)
Good example
| 1 | if (path.startsWith('/admin')) denyPublic(); |
Explanation (EN)
startsWith anchors the check to the intended position, avoiding accidental matches.
Objašnjenje (HR)
Notes (EN)
Use startsWith for prefixes and endsWith for suffixes. Reach for includes only when the marker can legitimately appear anywhere.