unicorn/no-unreadable-array-destructuring Style
它的作用
禁止以难以阅读的方式从数组中解构值。
为什么这不好?
解构非常有用,但它也可能让某些代码更难阅读。 此规则会阻止在从数组解构时忽略连续值(例如 let [,,foo] = array)。
示例
以下是此规则的错误代码示例:
javascript
const [, , foo] = parts;
const [, , ...rest] = parts;以下是此规则的正确代码示例:
javascript
const [foo] = parts;
const foo = parts[3];
const rest = parts.slice(2);
// 一个可以接受
const [, foo] = parts;如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/no-unreadable-array-destructuring": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/no-unreadable-array-destructuring": "error",
},
});bash
oxlint --deny unicorn/no-unreadable-array-destructuring版本
此规则在 v0.0.19 中加入。
