Skip to content

Add check for redundant whitespace alternations#52

Open
jvoisin wants to merge 1 commit into
thatch:masterfrom
jvoisin:ws
Open

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

Conversation

@jvoisin

@jvoisin jvoisin commented Jul 15, 2026

Copy link
Copy Markdown

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.
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.

1 participant