Skip to content

Add check for redundant whitespace alternations - #52

Merged
thatch merged 1 commit into
thatch:masterfrom
jvoisin:ws
Jul 25, 2026
Merged

Add check for redundant whitespace alternations#52
thatch merged 1 commit into
thatch:masterfrom
jvoisin:ws

Conversation

@jvoisin

@jvoisin jvoisin commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Flag patterns like (\n|\s+)+, (\n|\s)+ and (\s|\n)+ where an outer +/* repetition wraps a group whose alternation branches all match only whitespace subsumed by \s, with at least one branch being \s itself. Since \s already matches \n (and others), the alternation, group and outer quantifier are all redundant and the pattern simplifies to \s+.

This is the anti-pattern cleaned up in pygments/pygments#3186.

New checker 126 (check_redundant_whitespace_alternation), with tests.

Flag patterns like (\n|\s+)+, (\n|\s)+ and (\s|\n)+ where an outer +/*
repetition wraps a group whose alternation branches all match only
whitespace subsumed by \s, with at least one branch being \s itself.
Since \s already matches \n (and others), the alternation, group and outer
quantifier are all redundant and the pattern simplifies to \s+.

This is the anti-pattern cleaned up in pygments/pygments#3186.

New checker 126 (check_redundant_whitespace_alternation), with tests.
thatch added a commit that referenced this pull request Jul 25, 2026
check_redundant_whitespace_alternation (#52), check_dot_newline_alternation
(#53), and check_redundant_lookaround (#54) each independently claimed "126"
since they were written against the same base independently. Renumber to
126/127/128 respectively so each warning has a distinct, stable code.
@thatch
thatch merged commit 8aefcc2 into thatch:master Jul 25, 2026
thatch added a commit that referenced this pull request Jul 31, 2026
This is the second time independent PRs collided on the same message
id (126 across #52/#53/#54, now 129 across #55-#59). Statically walk
each check_/bygroups_check_/groups_check_ function's source for its
'num' assignment and assert none repeat, so a future collision fails
CI instead of silently shipping ambiguous warning codes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants