Find contradictory regex lookahead assertions

Proprietary

Marks a regular expression with a lookahead that contradicts what follows it, so that part of the pattern never matches. A positive lookahead is marked when a character it asserts cannot be the character required at the same position after it, as in (?=a)b or (?=ac)ab. A negative lookahead is marked when everything allowed after it starts with text the lookahead forbids, as in (?!a)ab. Where the whole input has to match, as in String.matches, Pattern.matches, Pattern.compile(..).matcher(..).matches() and Pattern.compile(..).asMatchPredicate(), a positive lookahead is also marked when it needs more characters than the rest of the pattern can consume, as in a(?=b). Only runs of single characters and character classes are compared, so a lookahead that holds an alternation, is optional or has a bounded repetition is not decided, and neither is anything past an anchor, a group, a back reference or a bounded repetition such as {2,3}. Lookbehinds are not checked. A pattern compiled with flags or holding inline flags is skipped, and so is a pattern that is not a string literal. Test sources are not searched.

io.moderne.staticanalysis.FindContradictoryLookahead
mod run . --recipe=io.moderne.staticanalysis.FindContradictoryLookahead

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.