Rules Hub

Coding Rules Library

← Back to all rules
fullstack ruleStack: general
gitclean-codereadabilityrefactoringcode-review

Minimize code churn by avoiding unnecessary reordering

Avoid moving blocks of code unless strictly necessary for logic or scoping, as it creates noisy diffs and complicates code reviews.

PR: Feat/FCK-2286 - Create new Heirs Kapital list page #4161Created: Dec 7, 2025

Bad example

Old codets
1function buildPage(req, res) {
2 const settings = getSettings();
3
4 // This block was originally AFTER logAnalytics
5 // Moving it up creates a large diff for no logical reason
6 const pageData = {
7 title: settings.title,
8 user: req.user,
9 newField: true // The only actual change
10 };
11
12 logAnalytics(req);
13
14 return res.render('page', pageData);
15}

Explanation (EN)

The developer moved the `pageData` definition above `logAnalytics` without any dependency requirement. This generates a confusing diff where lines appear deleted and added elsewhere, obscuring the fact that only `newField` was added.

Objašnjenje (HR)

Programer je premjestio definiciju `pageData` iznad `logAnalytics` bez ikakve logičke potrebe. To stvara zbunjujući diff u kojem linije izgledaju kao obrisane i dodane drugdje, skrivajući činjenicu da je samo dodano polje `newField`.

Good example

New codets
1function buildPage(req, res) {
2 const settings = getSettings();
3
4 logAnalytics(req); // Kept in original position
5
6 // The variable stays where it was, highlighting only the added line in the diff
7 const pageData = {
8 title: settings.title,
9 user: req.user,
10 newField: true
11 };
12
13 return res.render('page', pageData);
14}

Explanation (EN)

The code structure remains unchanged. The diff will clearly show only the insertion of `newField`, making the review process faster and the history cleaner.

Objašnjenje (HR)

Struktura koda ostaje nepromijenjena. Diff će jasno prikazati samo umetanje `newField`, što ubrzava pregled koda i održava povijest izmjena čistom.

Notes (EN)

Only move code if variable dependencies (scoping) require it. If you must refactor/reorder, do it in a separate commit from logic changes.

Bilješke (HR)

Premještajte kod samo ako to zahtijevaju ovisnosti varijabli (scope). Ako morate refaktorirati ili promijeniti redoslijed, učinite to u zasebnom commitu odvojenom od logičkih promjena.