no-empty-pattern
注意: 此规则是
recommended
规则集的一部分。在
deno.json
中启用完整规则集{ "lint": { "tags": ["recommended"] } }
使用 Deno CLI 启用完整规则集
deno lint --tags=recommended
禁止在解构中使用空模式。
在解构中,可以使用空模式,例如 {}
或 []
,但它们没有任何效果,很可能不是作者的本意。
无效
// 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 = []]) {}