eslint/sort-vars Pedantic
作用
强制对同一块作用域内的变量声明进行排序。
为什么这不好?
在同一块作用域内声明多个变量时,对变量名进行排序可以让以后更容易找到所需的变量。
未排序的变量声明会让代码更难阅读和维护。
示例
以下是此规则的错误代码示例:
js
var b, a;
var a, B, c;以下是此规则的正确代码示例:
js
var a, b, c, d;
var B, a, c;Configuration
This rule accepts a configuration object containing the following properties:
ignoreCase
type: boolean
default: false
When true, this rule will ignore case when sorting variables.
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"sort-vars": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"sort-vars": "error",
},
});bash
oxlint --deny sort-vars版本
此规则自 v0.9.3 起添加。
