Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Assign this magic number X to a well-named (variable|constant), and use the (variable|constant) instead.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Legacy Key:
      MagicNumber, COBOL.MagicNumberCheck
    • Targeted languages:
      Flex, PHP, Python, RPG, Swift, VB.Net
    • Covered Languages:
      ABAP, C#, C, C++, Cobol, Java, JavaScript, Objective-C, PL/SQL, TypeScript, VB6
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources
    • Checkstyle:
      MagicNumber
    • ESLint:
      no-magic-numbers
    • PMD:
      AvoidLiteralsInIfCondition

      Description

      A magic number is a number that comes out of nowhere, and is directly used in a statement. Magic numbers are often used, for instance to limit the number of iterations of a loop, to test the value of a property, etc.

      Using magic numbers may seem obvious and straightforward when you're writing a piece of code, but they are much less obvious and straightforward at debugging time.

      That is why magic numbers must be demystified by first being assigned to clearly named variables before being used.

      -1, 0 and 1 are not considered magic numbers.

        Attachments

          Issue Links

          1.
          RPG - Named constants should be used for indicators RSPEC-2049 Language-Specification Active Unassigned
          2.
          C-Family RSPEC-2904 Language-Specification Active Unassigned
          3.
          VB.NET RSPEC-3103 Language-Specification Active Unassigned
          4.
          Java RSPEC-3161 Language-Specification Active Unassigned
          5.
          JavaScript RSPEC-3162 Language-Specification Active Unassigned
          6.
          VB6 RSPEC-3163 Language-Specification Active Unassigned
          7.
          ABAP RSPEC-3164 Language-Specification Active Unassigned
          8.
          Cobol RSPEC-3569 Language-Specification Active Unassigned
          9.
          PL/SQL RSPEC-3570 Language-Specification Active Unassigned
          10.
          C# RSPEC-3572 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                freddy.mallet Freddy Mallet (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: