no-inner-declarations
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-inner-declarations": "error",
},
},
];Disallow variable or function declarations in nested blocks
// script, non-strict code
if (test) {
function doSomething() { }
}
function doSomethingElse() {
if (test) {
function doAnotherThing() { }
}
}
if (foo) function f(){}if (test) {
var foo = 42;
}
function doAnotherThing() {
if (test) {
var bar = 81;
}
}
if (foo) var a;
if (foo) function f(){}
class C {
static {
if (test) {
var something;
}
}
}// non-strict code
if (test) {
function doSomething() { }
}
function doSomething() {
if (test) {
function doSomethingElse() { }
}
}
// strict code
function foo() {
"use strict";
if (test) {
function bar() { }
}
}function doSomething() { }
function doSomethingElse() {
function doAnotherThing() { }
}
function doSomethingElse() {
"use strict";
if (test) {
function doAnotherThing() { }
}
}
class C {
static {
function doSomething() { }
}
}
if (test) {
asyncCall(id, function (err, data) { });
}
var fn;
if (test) {
fn = function fnExpression() { };
}
if (foo) var a;var bar = 42;
if (test) {
let baz = 43;
}
function doAnotherThing() {
var baz = 81;
}
class C {
static {
var something;
}
}function doSomething() { }
function doSomething() {
function doSomethingElse() { }
}Examples from the ESLint documentation.
no-inner-declarations
eslint
export default [
{
rules: {
"no-inner-declarations": "error",
},
},
];no-inner-declarations
eslint plugin · pedantic
{
"rules": {
"no-inner-declarations": "error"
}
}correctness/noInnerDeclarations
correctness · since 1.0.0
{
"linter": {
"rules": {
"correctness": {
"noInnerDeclarations": "error"
}
}
}
}Disallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals
Disallow returning value from constructor
Require template literals instead of string concatenation
Disallow the use of Math.pow in favor of the ** operator
Disallow unnecessary calls to .call() and .apply()
Enforce the use of the radix argument when using parseInt()