Prefer concise conditional expressions over verbose nested conditions and unnecessary boolean variables. This improves readability and reduces cognitive overhead.
Prefer concise conditional expressions over verbose nested conditions and unnecessary boolean variables. This improves readability and reduces cognitive overhead.
Key practices:
Examples:
Instead of nested conditions:
if (binding.binding && typeof binding.binding === "string") {
if (binding.binding.toUpperCase() === normalizedName) {
return true;
}
}
Combine into single condition:
if (typeof binding.binding === "string" && binding.binding.toUpperCase() === normalizedName) {
return true;
}
Instead of boolean tracking variables:
let isValid = false;
while (!isValid) {
// validation logic
if (validation.valid) {
isValid = true;
}
}
Use direct control flow:
while (true) {
// validation logic
if (validation.valid) {
return bindingName;
}
}
Instead of conditional assignment:
if (match) {
const cachedAssetKey = await match.text();
if (cachedAssetKey === assetKey) {
shouldUpdateCache = false;
}
}
Use direct assignment:
if (match) {
const cachedAssetKey = await match.text();
shouldUpdateCache = cachedAssetKey !== assetKey;
}
Enter the URL of a public GitHub repository