Skip to content

caughtVariableNames

Enforces a consistent naming convention for catch clause error variables.

✅ This rule is included in the ts stylisticStrict presets.

Consistent naming of catch clause parameters improves code readability. The preferred name is error, which clearly indicates the purpose of the variable. Descriptive names ending in “Error”, are also acceptable (e.g., innerError, parseError).

try {
doSomething();
} catch (e) {
console.log(e);
}
try {
readFile(path);
} catch (err) {
console.log(err);
}
try {
doSomething();
} catch (_) {
console.log("error occurred");
}

This rule is not configurable.

If your codebase has established conventions using different names like e, err, or ex, and changing them would require significant refactoring, you may disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.