Skip to content

Add check for single-character alternations (W129) - #57

Merged
thatch merged 1 commit into
thatch:masterfrom
jvoisin:alt
Jul 31, 2026
Merged

Add check for single-character alternations (W129)#57
thatch merged 1 commit into
thatch:masterfrom
jvoisin:alt

Conversation

@jvoisin

@jvoisin jvoisin commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Flag alternations whose every branch is a single foldable character and suggest the equivalent character class, which matches faster and reads more clearly: a|b|c -> [abc], \d||. -> [\d.], (a|b)c -> [ab]c.

Foldable atoms are plain literals, single-char escapes (., +, \x41, \, ...), builtin classes (\d \w \s \D \W \S) and \t/\n. Branches that would change meaning or break the class are left alone: multi-char runs (foo|bar), '.', anchors, groups, quantified atoms (a|b+) and a bare ']'.

Includes unit tests for the literal, builtin/escape, nested-in-group and the various no-flag cases.

Flag alternations whose every branch is a single foldable character and
suggest the equivalent character class, which matches faster and reads
more clearly: a|b|c -> [abc], \d|_|\. -> [\d_\.], (a|b)c -> [ab]c.

Foldable atoms are plain literals, single-char escapes (\., \+, \x41,
\\, ...), builtin classes (\d \w \s \D \W \S) and \t/\n. Branches that
would change meaning or break the class are left alone: multi-char runs
(foo|bar), '.', anchors, groups, quantified atoms (a|b+) and a bare ']'.

Includes unit tests for the literal, builtin/escape, nested-in-group and
the various no-flag cases.
@jvoisin
jvoisin marked this pull request as draft July 28, 2026 15:24
@jvoisin
jvoisin marked this pull request as ready for review July 28, 2026 15:31
thatch added a commit that referenced this pull request Jul 31, 2026
Renumber check_quantified_lookaround from 129 to 132; it collided
with checks added by #55/#56/#57 (129/130/131), since all were
written independently against the same base.
@thatch
thatch merged commit 0aeb59b into thatch:master Jul 31, 2026
0 of 15 checks passed
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