Skip to content
← Back to rules

eslint/no-var Restriction

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

它的作用

ECMAScript 2015 允许程序员使用 letconst 关键字创建具有块作用域的变量, 而不是函数作用域。块作用域在许多其他编程语言中都很常见,并且有助于 程序员避免错误。

为什么这不好?

在 ES2015 环境中使用 var 会触发此错误

示例

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

javascript
var x = "y";
var CONFIG = {};

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

javascript
let x = "y";
const CONFIG = {};

如何使用

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

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

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

版本

此规则于 v0.1.1 中添加。

参考资料