Skip to content

Add check for redundant lookarounds over assertions#54

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

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

Conversation

@jvoisin

@jvoisin jvoisin commented Jul 15, 2026

Copy link
Copy Markdown

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