no-redeclare
NOTE: this rule is part of the
recommended rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["recommended"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=recommended
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"lint": {
"rules": {
"include": ["no-redeclare"],
"exclude": ["no-redeclare"]
}
}
}Disallows redeclaration of variables, functions, parameters with the same name.
JavaScript allows us to redeclare variables with the same name using var, but
redeclaration should not be used since it can make variables hard to trace.
In addition, this lint rule disallows redeclaration using let or const as
well, although ESLint allows. This is useful because we can notice a syntax
error before actually running the code.
As for functions and parameters, JavaScript just treats these as runtime errors,
throwing SyntaxError when being run. It's also beneficial to detect this sort
of errors statically.
Invalid:
var a = 3;
var a = 10;
let b = 3;
let b = 10;
const c = 3;
const c = 10;
function d() {}
function d() {}
function e(arg: number) {
var arg: number;
}
function f(arg: number, arg: string) {}
Valid:
var a = 3;
function f() {
var a = 10;
}
if (foo) {
let b = 2;
} else {
let b = 3;
}