Skip to content

eslint/no-redeclare Pedantic ​

What it does ​

This rule disallows redeclaring variables within the same scope, ensuring that each variable is declared only once. It helps avoid confusion and unintended behavior in code.

Why is this bad? ​

Redeclaring variables in the same scope can lead to unexpected behavior, overwriting existing values, and making the code harder to understand and maintain.

Examples ​

Examples of incorrect code for this rule:

javascript
var a = 3;
var a = 10;

Examples of correct code for this rule:

javascript
var a = 3;
a = 10;

Options ​

builtinGlobals ​

{ type: bool, default: false }

When set true, it flags redeclaring built-in globals (e.g., let Object = 1;).

How to use ​

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

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

References ​

Released under the MIT License.