Skip to content

Magic numbers (MagicNumber)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL
OS
Minor Yes 1 badpractice

Parameters

Name Type Description Default value
authorizedNumbers String allowed numbers, coma separated. Example:-1,0,1,60 -1,0,1
allowMagicIndexes Boolean allow magic indexes true

Description

Magic numbers are any number in your code that does not immediately become apparent without being immersed in context.

Examples

Bad

Function GetsTheInterval(Duration)

     Return Duration < 10 * 60 * 60;

End Function

Good

Function GetsTheInterval (Duration in Seconds)

    MinutesHour     = 60;
    SecondsMinute   = 60;
    SecondsHour     = SecondsMinute * MinutesHour;
    HoursIninterval = 10;
    Return Duration < HoursWininterval * SecondsHour;

End Function

Snippets

Diagnostic ignorance in code

// BSLLS:MagicNumber-off
// BSLLS:MagicNumber-on

Parameter for config

"MagicNumber": {
    "authorizedNumbers": "-1,0,1",
    "allowMagicIndexes": true
}