Skip to content

redeclared-variable

Reports a name declared again in the same scope (var twice, a var and a parameter, two functions). In TypeScript files declaration merging (interfaces, namespaces, a class with an interface) is allowed. Built-in globals are not checked.

The second declaration replaces or merges with the first, so the earlier one is dead, and which of the two a use reaches depends on the order. It is usually a copy that should have had another name.

To fix, remove the repeat, or rename one of them.

Reported
...
function f(a, a2) { var a; return arguments; }
var x = 1; var x = 2; function x() {}
function f2() {} function f2() {}
...
js:
lint:
rules:
redeclared-variable: warn # off (default), warn, error
python:
lint:
rules:
redeclared-variable: warn # off (default), warn, error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, python/ruff.

Suppress one line with sudsy-disable-next-line redeclared-variable in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint no-redeclare partial the builtinGlobals option and /*global*/ comments are not supported (the files are modules, whose top scope is not the global scope)
ruff F811 full
typescript-eslint no-redeclare partial builtinGlobals and /*global*/ comments are not supported; ignoreDeclarationMerge keeps its default