Skip to content

regexZeroQuantifiers

Reports quantifiers with a maximum of zero, which are useless.

✅ This rule is included in the ts logical presets.

Reports quantifiers with a maximum of zero ({0} or {0,0}), which are useless because they match zero occurrences (the empty string). A quantifier with a maximum of 0 means the quantified element will never be matched, so both the quantifier and its element can be removed.

const pattern = /a{0}/;

The {0} quantifier means a will never be matched, making the entire quantified expression useless.

const pattern = /a{0,0}/;

The {0,0} quantifier also means exactly zero matches, making it equivalent to an empty match.

const pattern = /(ab){0}/;

The group (ab) with {0} will never match anything useful.

const pattern = /[a-z]{0}/;

The character class [a-z] with {0} will never match any character.

This rule is not configurable.

There is no valid use case for a quantifier with a maximum of 0, so this rule should generally always be enabled.

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