Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Latest commit

 

History

History
25 lines (16 loc) · 1.05 KB

no-unnecessary-quantifier.md

File metadata and controls

25 lines (16 loc) · 1.05 KB

no-unnecessary-quantifier 🔧

Disallow unnecessary quantifiers.

configuration in plugin:clean-regex/recommended: "warn"

Source file
Test file

Description

Unnecessary quantifiers are quantifiers which can be removed without changing the meaning of the pattern.

A trivial example is: a{1}
Obviously, the quantifier can be removed.

This is the only auto-fixable unnecessary quantifier. All other unnecessary quantifiers hint at programmer oversight or fundamental problems with the pattern.

A not-so-trivial example is: (?:a+b*|c*)?
It's not very obvious that the ? quantifier can be removed. Without this quantifier, that pattern can still match the empty string by choosing 0 many c in the c* alternative.

Other examples include (?:\b|(?=%))+ and (?:|(?:)){5,9}.