useDestructuring
¥Summary
-
规则生效日期:
v2.3.9¥Rule available since:
v2.3.9 -
诊断类别:
lint/nursery/useDestructuring¥Diagnostic Category:
lint/nursery/useDestructuring -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
prefer-destructuring相同¥Same as
prefer-destructuring
-
¥How to configure
{ "linter": { "rules": { "nursery": { "useDestructuring": "error" } } }}¥Description
要求从数组和/或对象中解构赋值。
¥Require destructuring from arrays and/or objects
JavaScript ES6 新增了一种语法,用于从数组索引或对象属性创建变量,称为解构赋值。此规则强制要求使用解构赋值,而不是通过成员表达式访问属性。
¥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.
¥Examples
¥Invalid
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.
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.
¥Valid
var [foo] = array;var { bar } = foo;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号