Is there an eslint rule to enforce that variables are declared at the top of the block? The vars-on-top
rule seems to literally only apply to the var
keyword, and is not what I want (e.g. it would disallow for (var i = 0; ...)
. Here is a contrived example.
Bad Code
doWork() {
const work = this.getWork();
if (work.isReady) { ... }
let workResult = work.getResult();
// ...
return workResult;
}
Good Code
doWork() {
const work = this.getWork();
let workResult;
if (work.isReady) { ... }
workResult = work.getResult();
// ...
return workResult;
}