no-case-declarations
eslint
SuggestionRecommended
eslint.config.js
export default [
{
rules: {
"no-case-declarations": "error",
},
},
];switch (foo) {
case 1:
let x = 1;
break;
case 2:
const y = 2;
break;
case 3:
function f() {}
break;
default:
class C {}
}// Declarations outside switch-statements are valid
const a = 0;
switch (foo) {
// The following case clauses are wrapped into blocks using brackets
case 1: {
let x = 1;
break;
}
case 2: {
const y = 2;
break;
}
case 3: {
function f() {}
break;
}
case 4:
// Declarations using var without brackets are valid due to function-scope hoisting
var z = 4;
break;
default: {
class C {}
}
}Examples from the ESLint documentation.
no-case-declarations
eslint
export default [
{
rules: {
"no-case-declarations": "error",
},
},
];no-case-declarations
eslint plugin · pedantic
{
"rules": {
"no-case-declarations": "error"
}
}correctness/noSwitchDeclarations
correctness · since 1.0.0
{
"linter": {
"rules": {
"correctness": {
"noSwitchDeclarations": "error"
}
}
}
}Disallow duplicate arguments in function definitions
Disallow calling some Object.prototype methods directly on objects
Require const declarations for variables that are never reassigned after declared
Disallow new operators with global non-constructor functions
Require rest parameters instead of arguments