no-useless-error-capture-stack-trace

March 27, 2026 ยท View on GitHub

๐Ÿ“ Disallow unnecessary Error.captureStackTrace(โ€ฆ).

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

Calling Error.captureStackTrace(โ€ฆ) inside the constructor of a built-in Error subclass is unnecessary, since the Error constructor calls it automatically.

Examples

// โŒ
class MyError extends Error {
	constructor() {
		Error.captureStackTrace(this, MyError);
	}
}
// โŒ
class MyError extends Error {
	constructor() {
		Error.captureStackTrace?.(this, MyError);
	}
}
// โŒ
class MyError extends Error {
	constructor() {
		Error.captureStackTrace(this, this.constructor);
	}
}
// โŒ
class MyError extends Error {
	constructor() {
		Error.captureStackTrace?.(this, this.constructor);
	}
}
// โŒ
class MyError extends Error {
	constructor() {
		Error.captureStackTrace(this, new.target);
	}
}
// โŒ
class MyError extends Error {
	constructor() {
		Error.captureStackTrace?.(this, new.target);
	}
}