Skip to content

eslint/no-var Restriction

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

What it does

ECMAScript 6 allows programmers to create variables with block scope instead of function scope using the let and const keywords. Block scope is common in many other programming languages and helps programmers avoid mistakes.

Why is this bad?

Using var in an es6 environment triggers this error

Examples

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

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

How to use

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

bash
oxlint --deny no-var
json
{
  "rules": {
    "no-var": "error"
  }
}

References

Released under the MIT License.