no-throw-literal
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-throw-literal": "error",
},
},
];throw "error";
throw 0;
throw undefined;
throw null;
const err = new Error();
throw "an " + err;
// err is recast to a string literal
const er2 = new Error();
throw `${err2}`throw new Error();
throw new Error("error");
const e = new Error("error");
throw e;
try {
throw new Error("error");
} catch (e) {
throw e;
}Examples from the ESLint documentation.
no-throw-literal
eslint
export default [
{
rules: {
"no-throw-literal": "error",
},
},
];no-throw-literal
eslint plugin · pedantic
{
"rules": {
"no-throw-literal": "error"
}
}style/useThrowOnlyError
style · since 1.8.0
{
"linter": {
"rules": {
"style": {
"useThrowOnlyError": "error"
}
}
}
}Disallow unnecessary computed property keys in objects and classes
Require or disallow Unicode byte order mark (BOM)
Disallow new operators with the Function object
Disallow unnecessary calls to .bind()