Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3757

Arithmetic operations should not result in "NaN"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Hide
      Change the expression which uses this operand so that it can't evaluate to "NaN" (Not a Number).
      Show
      Change the expression which uses this operand so that it can't evaluate to "NaN" (Not a Number).
    • Highlighting:
      Hide

      Primary: operand triggering the rule
      Secondary: operator
      Secondary: second operand

      Show
      Primary: operand triggering the rule Secondary: operator Secondary: second operand
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way recommended
    • Covered Languages:
      JavaScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      The result of an expression with an arithmetic operator /, *, %, ++, --, -, +=, -=, *=, /=, %=, + or unary operator +, - when at least one operand is Object or Undefined will be always a NaN (Not a Number).

      Noncompliant Code Example

      x = [1, 2];
      var y = x / 4;  //Noncompliant
      

      Exceptions

      • Date operands: they are implicitly converted to numbers.
      • The binary + operator with Object operand (concatenation).

        Attachments

          Activity

            People

            Assignee:
            pierre-yves.nicolas Pierre-Yves Nicolas
            Reporter:
            jeanchristophe.collet Jean-Christophe Collet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: