Skip to content

Add check for (.|\n) any-character alternations - #53

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

Add check for (.|\n) any-character alternations#53
thatch merged 1 commit into
thatch:masterfrom
jvoisin:alternation

Conversation

@jvoisin

@jvoisin jvoisin commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Flag alternations that match every character by combining . with \n (optionally with extra single-char branches like \r), e.g. (.|\n)*?. Since . already matches all but \n, this is the [\s\S] idiom spelled out as a per-character alternation, which is much slower to match than a single character class.

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

New checker 126 (check_dot_newline_alternation), with tests.

Flag alternations that match every character by combining . with \n
(optionally with extra single-char branches like \r), e.g. (.|\n)*?.
Since . already matches all but \n, this is the [\s\S] idiom spelled
out as a per-character alternation, which is much slower to match than
a single character class.

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

New checker 126 (check_dot_newline_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 1f1d9c8 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