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

The output of functions that don't return anything should not be used

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Remove this use of the output from "xxx"; "xxx" doesn't return anything.
    • Highlighting:
      • Primary:
        • x = noReturn(...)
        • doSomething(noReturn(...))
      • Secondary: function definition
        • 'Function definition.'
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way, Sonar way recommended
    • Targeted languages:
      Python
    • Covered Languages:
      JavaScript, PHP, TypeScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources
    • ESLint-SonarJS:
      no-use-of-empty-return-value
    • TSLint:
      no-void-expression
    • TSLint-SonarTS:
      no-use-of-empty-return-value

      Description

      If a function does not return anything, it makes no sense to use its output. Specifically, passing it to another function, or assigning its "result" to a variable is probably a bug because such functions return undefined, which is probably not what was intended.

      Noncompliant Code Example

      function foo() {
        console.log("Hello, World!");
      }
      
      a = foo();
      

      Compliant Solution

      function foo() {
        console.log("Hello, World!");
      }
      
      foo();
      

        Attachments

          Issue Links

          1.
          PHP RSPEC-4312 Language-Specification Active Unassigned
          2.
          JavaScript RSPEC-5177 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              yves.duboispelerin Yves Dubois-Pèlerin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: