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).
Verify a regex against real input, not just its source
Test a copied regex against actual example strings before trusting it.
Bad example
| 1 | const MULTI_PERSON_NAME = /\s+(\/|og|,|-|–)\s+/; |
| 2 | // "Anna Berg, Per Nilsen" does not match: no space before the comma |
Explanation (EN)
The pattern requires whitespace on both sides of the separator, but a comma-separated name realistically has no space before the comma, so the exact input this was built to catch slips through unmatched.
Objašnjenje (HR)
Uzorak zahtijeva razmak s obje strane separatora, no ime odvojeno zarezom realno nema razmak prije zareza, pa upravo onaj unos koji je trebao uhvatiti prođe nezamijećen.
Good example
| 1 | const MULTI_PERSON_NAME = /\s*[,/]\s+|\s+(og|–|-)\s+/; |
| 2 | // matches with or without a space before the comma/slash |
Explanation (EN)
Write a couple of realistic sample inputs (with and without the space) as an inline comment or quick test before shipping a regex, rather than assuming a plausible-looking pattern is correct.
Objašnjenje (HR)
Napiši nekoliko realnih primjera unosa (s razmakom i bez njega) kao inline komentar ili brzi test prije nego što regex ode u produkciju, umjesto da pretpostaviš da uvjerljivo izgledajući uzorak radi ispravno.
Notes (EN)
When copying a pattern from another repository, name that source accurately — pointing at the wrong file/function makes the pattern harder to trace and re-verify later.
Bilješke (HR)
Kad kopiraš uzorak iz drugog repozitorija, precizno navedi taj izvor — upućivanje na pogrešan file/funkciju otežava kasnije praćenje i ponovnu provjeru uzorka.