Aller au contenu

Magic Number (ARCH3182)

Ce contenu n’est pas encore disponible dans votre langue.

Key typescript.quality.magic-number · Severity info · Category quality

Unnamed numeric literals inside expressions hide what they mean, and become hard to maintain when the same value is repeated. They should be extracted into named constants.

function priceWithTax(net: number): number {
return net * 1.18 + 30;
}
const VAT_RATE = 0.18;
const SHIPPING_FEE = 30;
function priceWithTax(net: number): number {
return net * (1 + VAT_RATE) + SHIPPING_FEE;
}

Extract numeric literals into descriptively named const or enum values.