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

Destructuring patterns should not be empty

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Change this pattern to not be empty.
    • Highlighting:
      Hide

      empty destructuring pattern

      Show
      empty destructuring pattern
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way, Sonar way recommended
    • Covered Languages:
      JavaScript, TypeScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources
    • ESLint:
      no-empty-pattern
    • TSLint-SonarTS:
      no-empty-destructuring

      Description

      Destructuring is a convenient way of extracting multiple values from data stored in (possibly nested) objects and arrays. However, it is possible to create an empty pattern that has no effect. When empty curly braces or brackets are used to the right of a property name most of the time the intent was to use a default value instead.

      This rule raises an issue when empty destructuring pattern is used.

      Noncompliant Code Example

      var {a: {}, b} = myObj; // Noncompliant
      function foo({first: [], second}) { // Noncompliant
        // ...
      }
      

      Compliant Solution

      var {a = {}, b} = myObj;
      function foo({first = [], second}) {
        // ...
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jeanchristophe.collet Jean-Christophe Collet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: