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).
Remove intermediate conversion steps that don't affect the final result
If a parsing/normalization/conversion step is a no-op for the output (because a later call already handles it), delete it instead of leaving redundant transformations.
Bad example
| 1 | const parsedDateTime = parse(date, "yyyy-MM-dd'T'HH:mm:ss", new Date()); |
| 2 | // formatTz already applies { timeZone }, so this UTC round-trip changes nothing |
| 3 | // in the output and risks a double conversion / DST edge case. |
| 4 | const utcTime = fromZonedTime(parsedDateTime, this.timezone); |
| 5 | return formatTz(utcTime, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", { timeZone: this.timezone }); |
Explanation (EN)
The `fromZonedTime` step does not change the formatted output because `formatTz` already applies the timezone. Keeping it adds a misleading transformation and a real risk of double-converting across DST boundaries.
Objašnjenje (HR)
Korak `fromZonedTime` ne mijenja formatirani izlaz jer `formatTz` vec primjenjuje vremensku zonu. Zadrzavanje ga cini zavaravajucom transformacijom i stvarnim rizikom dvostruke konverzije preko granica ljetnog/zimskog vremena.
Good example
| 1 | const parsedDateTime = parse(date, "yyyy-MM-dd'T'HH:mm:ss", new Date()); |
| 2 | return formatTz(parsedDateTime, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", { timeZone: this.timezone }); |
Explanation (EN)
Once you verify the later call already handles the conversion, the intermediate step is dropped. The pipeline is shorter, has fewer ways to be wrong, and matches what actually runs.
Objašnjenje (HR)
Nakon sto potvrdis da kasniji poziv vec obavlja konverziju, medukorak se izbacuje. Cjevovod je kraci, ima manje nacina da bude pogresan i odgovara onome sto se stvarno izvrsava.
Notes (EN)
Pair removal with a test that pins the expected output so a future reader does not re-add the 'safety' step.
Bilješke (HR)
Uz uklanjanje dodaj test koji fiksira ocekivani izlaz kako buduci citatelj ne bi ponovno dodao 'sigurnosni' korak.
Exceptions / Tradeoffs (EN)
Only remove a step after confirming (ideally with a test) that it does not change the result for the relevant inputs, including edge cases like DST transitions.
Iznimke / Tradeoffi (HR)
Ukloni korak tek nakon sto potvrdis (idealno testom) da ne mijenja rezultat za relevantne ulaze, ukljucujuci rubne slucajeve poput prijelaza na ljetno/zimsko vrijeme.