Details
-
Type:
Bug Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:None
-
Message:Change this pattern to not be empty.
-
Highlighting:
-
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}) { // ... }