Skip to content

noRedeclare (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"suspicious": {
"noRedeclare": "error"
}
}
}
}

Disallow variable, function, class, and type redeclarations in the same scope.

var a = 3;
var a = 10;
code-block.js:2:5 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ 'a' is redeclared in the same scope.

1 │ var a = 3;
> 2 │ var a = 10;
│ ^
3 │

ℹ 'a' is defined here:

> 1 │ var a = 3;
│ ^
2 │ var a = 10;
3 │

ℹ Redeclarations make it unclear which variable a reference points to and can hide earlier declarations.

ℹ Remove the duplicate declaration or rename one of the variables.

let a = 3;
let a = 10;
code-block.js:2:5 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ 'a' is redeclared in the same scope.

1 │ let a = 3;
> 2 │ let a = 10;
│ ^
3 │

ℹ 'a' is defined here:

> 1 │ let a = 3;
│ ^
2 │ let a = 10;
3 │

ℹ Redeclarations make it unclear which variable a reference points to and can hide earlier declarations.

ℹ Remove the duplicate declaration or rename one of the variables.

function f() {}
function f() {}
code-block.js:2:10 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ 'f' is redeclared in the same scope.

1 │ function f() {}
> 2 │ function f() {}
│ ^
3 │

ℹ 'f' is defined here:

> 1 │ function f() {}
│ ^
2 │ function f() {}
3 │

ℹ Redeclarations make it unclear which variable a reference points to and can hide earlier declarations.

ℹ Remove the duplicate declaration or rename one of the variables.

class C {
static {
var c = 3;
var c = 10;
}
}
code-block.js:4:13 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ 'c' is redeclared in the same scope.

2 │ static {
3 │ var c = 3;
> 4 │ var c = 10;
│ ^
5 │ }
6 │ }

ℹ 'c' is defined here:

1 │ class C {
2 │ static {
> 3 │ var c = 3;
│ ^
4 │ var c = 10;
5 │ }

ℹ Redeclarations make it unclear which variable a reference points to and can hide earlier declarations.

ℹ Remove the duplicate declaration or rename one of the variables.

type Person = { name: string; }
class Person { name: string; }
code-block.ts:2:7 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ 'Person' is redeclared in the same scope.

1 │ type Person = { name: string; }
> 2 │ class Person { name: string; }
│ ^^^^^^
3 │

ℹ 'Person' is defined here:

> 1 │ type Person = { name: string; }
│ ^^^^^^
2 │ class Person { name: string; }
3 │

ℹ Redeclarations make it unclear which variable a reference points to and can hide earlier declarations.

ℹ Remove the duplicate declaration or rename one of the variables.

var a = 3;
a = 10;
class Foo {
bar(a: A);
bar(a: A, b: B);
bar(a: A, b: B) {}
}