noRedeclare
Diagnostic Category: lint/suspicious/noRedeclare
Since: v1.0.0
Sources:
- Same as:
no-redeclare
- Same as:
@typescript-eslint/no-redeclare
Disallow variable, function, class, and type redeclarations in the same scope.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:2:5 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘a’. Consider to delete it or rename it.
1 │ var a = 3;
> 2 │ var a = 10;
│ ^
3 │
ℹ ‘a’ is defined here:
> 1 │ var a = 3;
│ ^
2 │ var a = 10;
3 │
code-block.js:2:5 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘a’. Consider to delete it or rename it.
1 │ let a = 3;
> 2 │ let a = 10;
│ ^
3 │
ℹ ‘a’ is defined here:
> 1 │ let a = 3;
│ ^
2 │ let a = 10;
3 │
code-block.js:2:10 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘f’. Consider to delete it or rename it.
1 │ function f() {}
> 2 │ function f() {}
│ ^
3 │
ℹ ‘f’ is defined here:
> 1 │ function f() {}
│ ^
2 │ function f() {}
3 │
code-block.js:4:13 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘c’. Consider to delete it or rename it.
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 │ }
code-block.ts:2:7 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘Person’. Consider to delete it or rename it.
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 │