Skip to content
← Back to rules

eslint/sort-vars Pedantic

🚧 An auto-fix is planned for this rule, but not implemented at this time.

作用

当在同一个代码块中声明多个变量时,对变量名进行排序会让 以后更容易找到所需的变量。

为什么这不好?

未排序的变量声明会让代码更难阅读和维护。

示例

以下是此规则的错误代码示例:

js
var b, a;
var a, B, c;

以下是此规则的正确代码示例:

js
var a, b, c, d;
var B, a, c;

配置

此规则接受一个包含以下属性的配置对象:

ignoreCase

type: boolean

default: false

当为 true 时,该规则在对变量排序时会忽略大小写。

如何使用

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 起添加。

参考资料