Skip to content
← Back to rules

eslint/one-var 样式

🛠️ An auto-fix is available for this rule for some violations.

作用

强制变量以合并或分开的方式进行声明。

为什么这不好?

一致的声明分组方式可以让变量生命周期和初始化模式更易于浏览。此规则可以要求每个作用域使用一个声明、每条语句使用一个声明器,或仅对连续的声明进行分组。

示例

此规则的错误代码示例:

js
var foo = 1;
var bar = 2;

此规则的正确代码示例:

js
var foo = 1,
  bar = 2;

配置

强制变量声明采用一致的分组方式。

类型:object

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "one-var": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "one-var": "error",
  },
});
bash
oxlint --deny one-var

版本

此规则于 v1.78.0 中新增。

参考