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

Unused assignments should be removed

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove this assignment to local variable “xxx”; the value is never used.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      ABAP, Flex, PL/I, RPG, T-SQL, VB.Net, VB6
    • Covered Languages:
      C#, C, C++, Java, JavaScript, Objective-C, PHP, PL/SQL, Python, Swift, TypeScript
    • Irrelevant for Languages:
      Cobol, HTML, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      15min
    • Analysis Level:
      Control-flow Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Implementation details:
    • Common Rule:
      Yes
    • CERT:
      MSC13-C., MSC56-J.
    • CWE:
      CWE-563
    • CPPCheck:
      redundantAssignInSwitch, redundantAssignment, redundantCopy, redundantCopyInSwitch, unreadVariable, unusedAllocatedMemory
    • FindBugs:
      DLS_DEAD_LOCAL_STORE, DLS_DEAD_LOCAL_STORE_OF_NULL, DLS_DEAD_LOCAL_STORE_SHADOWS_FIELD, DLS_DEAD_STORE_OF_CLASS_LITERAL, SF_DEAD_STORE.*
    • FxCop:
      RemoveUnusedLocals
    • PC-Lint:
      438, 1438, 551, 552, 1552, 838, 1838
    • ReSharper:
      RedundantAssignment
    • TSLint-SonarTS:
      no-dead-store

      Description

      A dead store happens when a local variable is assigned a value that is not read by any subsequent instruction. Calculating or retrieving a value only to then overwrite it or throw it away, could indicate a serious error in the code. Even if it's not an error, it is at best a waste of resources. Therefore all calculated values should be used.

      Noncompliant Code Example

      i = a + b; // Noncompliant; calculation result not used before value is overwritten
      i = compute();
      

      Compliant Solution

      i = a + b;
      i += compute();
      

      Exceptions

      This rule ignores initializations to -1, 0, 1, null, true, false and "".

      See

        Attachments

          Issue Links

          1.
          JavaScript RSPEC-1856 Language-Specification Active Unassigned
          2.
          C-Family RSPEC-1869 Language-Specification Active Unassigned
          3.
          PHP RSPEC-1870 Language-Specification Active Unassigned
          4.
          C# RSPEC-3492 Language-Specification Active Unassigned
          5.
          Python RSPEC-3988 Language-Specification Active Unassigned
          6.
          Swift RSPEC-4533 Language-Specification Active Unassigned
          7.
          PL/SQL RSPEC-5242 Language-Specification Active Unassigned

            Activity

              People

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

                Dates

                Created:
                Updated: