禁止空解构模式
注意:此规则是
recommended
规则集的一部分。在
deno.json
中启用完整集合{ "lint": { "rules": { "tags": ["recommended"] } } }
使用 Deno CLI 启用完整集合
deno lint --rules-tags=recommended
可以通过将其添加到
deno.json
文件中的 include
或 exclude
数组中,显式地将此规则包含或排除在当前标签中存在的规则之外。{ "lint": { "rules": { "include": ["no-empty-pattern"], "exclude": ["no-empty-pattern"] } } }
禁止在解构中使用空模式。
在解构中,可以使用空模式,例如 {}
或 []
,这些模式没有任何效果,很可能不是作者的本意。
无效示例
// In these examples below, {} and [] are not object literals or empty arrays,
// but placeholders for destructured variable names
const {} = someObj;
const [] = someArray;
const {a: {}} = someObj;
const [a: []] = someArray;
function myFunc({}) {}
function myFunc([]) {}
有效示例
const { a } = someObj;
const [a] = someArray;
// Correct way to default destructured variable to object literal
const { a = {} } = someObj;
// Correct way to default destructured variable to empty array
const [a = []] = someArray;
function myFunc({ a }) {}
function myFunc({ a = {} }) {}
function myFunc([a]) {}
function myFunc([a = []]) {}