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).
Avoid redundant variable aliases
Do not create variables that merely alias existing state or props without adding logic or semantic value.
Bad example
| 1 | const [results, setResults] = useState<Item[]>([]); |
| 2 |
|
| 3 | // Bad: 'visible' is just a direct reference to 'results' with no transformation |
| 4 | const visible = results; |
| 5 |
|
| 6 | return ( |
| 7 | <ul> |
| 8 | {visible.map((item) => ( |
| 9 | <li key={item.id}>{item.name}</li> |
| 10 | ))} |
| 11 | </ul> |
| 12 | ); |
Explanation (EN)
The variable `visible` is an unnecessary alias for `results`. It introduces visual noise and confuses the reader into thinking there might be a difference between the two variables when there isn't.
Objašnjenje (HR)
Varijabla `visible` je nepotreban alias za `results`. Unosi vizualni šum i zbunjuje čitatelja stvarajući dojam da postoji razlika između te dvije varijable, iako je nema.
Good example
| 1 | const [results, setResults] = useState<Item[]>([]); |
| 2 |
|
| 3 | // Good: Use the state variable directly |
| 4 | return ( |
| 5 | <ul> |
| 6 | {results.map((item) => ( |
| 7 | <li key={item.id}>{item.name}</li> |
| 8 | ))} |
| 9 | </ul> |
| 10 | ); |
Explanation (EN)
Removing the alias simplifies the code. The variable `results` is already descriptive enough, and using it directly reduces the number of symbols the developer needs to track.
Objašnjenje (HR)
Uklanjanje aliasa pojednostavljuje kod. Varijabla `results` je već dovoljno opisna, a njeno izravno korištenje smanjuje broj simbola koje programer mora pratiti.
Notes (EN)
If you need to rename a variable for clarity, rename the original state or prop instead of creating an alias.
Bilješke (HR)
Ako trebaš preimenovati varijablu radi jasnoće, preimenuj izvorno stanje ili prop umjesto stvaranja aliasa.