Rules Hub

Coding Rules Library

← Back to all rules
fullstack ruleStack: general
namingclean-codereadabilitytypescript

Restrict boolean prefixes to boolean values

Variables named with boolean prefixes (is, has, should) must strictly hold boolean values to ensure code clarity.

PR: Feat/FCK-2259 - Show category label on market news articles #4152Created: Dec 7, 2025

Bad example

Old codets
1// 'hasLabel' sounds like a boolean, but holds a string
2const hasLabel = data.labels?.[0];
3
4// 'tickerCategory' is ambiguous: is it a category OF tickers?
5const tickerCategory = currentCategory || (hasLabel && { label: hasLabel });
6
7if (hasLabel) { // Works in JS, but confusing to read
8 console.log(hasLabel.toUpperCase());
9}

Explanation (EN)

The variable `hasLabel` uses the `has` prefix, which conventionally indicates a boolean, but it holds a string. This mismatch creates confusion about the variable's type. Additionally, `tickerCategory` describes where the data is used (ticker) rather than what the data is (article category), making it misleading.

Objašnjenje (HR)

Varijabla `hasLabel` koristi prefiks `has`, koji konvencionalno označava boolean, ali sadrži string. Ovo nepodudaranje stvara zbrku oko tipa varijable. Također, `tickerCategory` opisuje gdje se podatak koristi (ticker), a ne što podatak zapravo jest (kategorija članka), što navodi na krivi zaključak.

Good example

New codets
1// Noun for the value, Boolean for the check
2const labelName = data.labels?.[0];
3const hasLabel = Boolean(labelName);
4
5// Name describes the entity (Article Category), not the UI component
6const articleCategory = currentCategory || (labelName ? { label: labelName } : undefined);
7
8if (hasLabel) {
9 console.log(labelName.toUpperCase());
10}

Explanation (EN)

The string value is assigned to a noun-based variable (`labelName`), and the boolean check is explicit (`hasLabel`). The configuration object is renamed to `articleCategory` to accurately reflect the domain entity it represents, regardless of where it is rendered.

Objašnjenje (HR)

String vrijednost je dodijeljena imenici (`labelName`), a booleova provjera je eksplicitna (`hasLabel`). Konfiguracijski objekt je preimenovan u `articleCategory` kako bi točno odražavao domenski entitet koji predstavlja, bez obzira na to gdje se prikazuje.