跳转到内容

useDestructuring

此内容尚不支持你的语言。

biome.json
{
"linter": {
"rules": {
"nursery": {
"useDestructuring": "error"
}
}
}
}

Require destructuring from arrays and/or objects

With JavaScript ES6, a new syntax was added for creating variables from an array index or object property, called destructuring. This rule enforces usage of destructuring instead of accessing a property through a member expression.

var foo = array[0];
code-block.js:1:5 lint/nursery/useDestructuring ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use array destructuring instead of accessing array elements by index.

> 1 │ var foo = array[0];
^^^^^^^^^^^^^^
2 │

Array destructuring is more readable and expressive than accessing individual elements by index.

Replace the array index access with array destructuring syntax.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

var bar = foo.bar;
code-block.js:1:5 lint/nursery/useDestructuring ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use object destructuring instead of accessing object properties.

> 1 │ var bar = foo.bar;
^^^^^^^^^^^^^
2 │

Object destructuring is more readable and expressive than accessing individual properties.

Replace the property access with object destructuring syntax.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

var [foo] = array;
var { bar } = foo;