eslint/no-var Restriction
它的作用
ECMAScript 2015 允许程序员使用 let 和 const 关键字创建具有块作用域的变量, 而不是函数作用域。块作用域在许多其他编程语言中都很常见,并且有助于 程序员避免错误。
为什么这不好?
在 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 中添加。
