Skip to content

Add check for redundant lookarounds over assertions - #54

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

Add check for redundant lookarounds over assertions#54
thatch merged 1 commit into
thatch:masterfrom
jvoisin:ar

Conversation

@jvoisin

@jvoisin jvoisin commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Flag zero-width lookarounds that wrap a single boundary/anchor assertion, since a lookaround over a zero-width assertion is just the assertion itself:

(?=\b)/(?<=\b) -> \b, (?<=^) -> ^, (?=$) -> $, etc.
(?!\b)/(?<!\b) -> \B (\b is the only anchor with a named negation)

Negative lookarounds over other anchors have no simple replacement and are left alone, as are lookarounds wrapping more than a bare assertion.

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

New checker 126 (check_redundant_lookaround), with tests.

Flag zero-width lookarounds that wrap a single boundary/anchor
assertion, since a lookaround over a zero-width assertion is just the
assertion itself:

  (?=\b)/(?<=\b) -> \b, (?<=^) -> ^, (?=$) -> $, etc.
  (?!\b)/(?<!\b) -> \B  (\b is the only anchor with a named negation)

Negative lookarounds over other anchors have no simple replacement and
are left alone, as are lookarounds wrapping more than a bare assertion.

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

New checker 126 (check_redundant_lookaround), 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 9147c79 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