consistent-assert-throws-callback-style

July 3, 2026 ยท View on GitHub

๐Ÿ“ Enforce a consistent body style for assert.throws() arrow callbacks.

๐Ÿšซ This rule is disabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

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

Enforces block or expression bodies for assert.throws() arrow callbacks.

It is off by default. Set your preferred style.

The default block style fixes expression bodies to block bodies. The original expression is evaluated as a non-returned expression statement.

The expression style reports only single-expression block bodies. Multi-statement blocks and throw cannot be converted.

Autofix is skipped for async callbacks, explicit return types, unsafe comment moves, and split-line arrows.

Options

  • style ('block' | 'expression', default 'block') โ€” which callback body style to require.
{
	'node-test/consistent-assert-throws-callback-style': ['error', {style: 'block'}]
}

Examples

With the default {style: 'block'}:

import assert from 'node:assert';

// โŒ
assert.throws(() => parse(input), SyntaxError);

// โœ…
assert.throws(() => {
	parse(input);
}, SyntaxError);

With {style: 'expression'}:

import assert from 'node:assert';

// โŒ
assert.throws(() => {
	parse(input);
}, SyntaxError);

// โœ…
assert.throws(() => parse(input), SyntaxError);