no-assert-match-string

July 3, 2026 ยท View on GitHub

๐Ÿ“ Disallow strings as the regexp argument of assert.match()/assert.doesNotMatch().

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

๐Ÿ’ก This rule is manually fixable by editor suggestions.

assert.match(value, regexp[, message]) and assert.doesNotMatch(value, regexp[, message]) require a RegExp as the second argument. Passing a string throws TypeError ERR_INVALID_ARG_TYPE at runtime instead of checking the value.

This rule reports a string or template literal passed as the regexp argument. It can suggest wrapping the string in new RegExp() or, when the string is meant to be the exact expected value, changing the assertion to assert.strictEqual()/assert.notStrictEqual(). It is separate from prefer-assert-match, which rewrites other assertion styles to assert.match().

Examples

import assert from 'node:assert';

// โŒ
assert.match(value, 'foo');
assert.doesNotMatch(value, 'foo');

// โœ…
assert.match(value, /foo/);
assert.doesNotMatch(value, /foo/);
assert.match(value, new RegExp('foo'));