Skip to content

noEmptyPattern

诊断类别:lint/correctness/noEmptyPattern

¥Diagnostic Category: lint/correctness/noEmptyPattern

自从:v1.0.0

¥Since: v1.0.0

来源:

¥Sources:

禁止空的解构模式。

¥Disallows empty destructuring patterns.

¥Examples

¥Invalid

var {} = foo;
code-block.js:1:5 lint/correctness/noEmptyPattern ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected empty object pattern.

> 1 │ var {} = foo;
^^
2 │

var {a: {}} = foo;
code-block.js:1:9 lint/correctness/noEmptyPattern ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected empty object pattern.

> 1 │ var {a: {}} = foo;
^^
2 │

function foo({}) {}
code-block.js:1:14 lint/correctness/noEmptyPattern ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected empty object pattern.

> 1 │ function foo({}) {}
^^
2 │

¥Valid

以下情况有效,因为它们会创建新的绑定。

¥The following cases are valid because they create new bindings.

var {a = {}} = foo;
var {a, b = {}} = foo;
var {a = []} = foo;
function foo({a = {}}) {}
function foo({a = []}) {}
var [a] = foo;

¥Related links