realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.46k stars 2.2k forks source link

Custom rule using lookbehind becomes Invalid configuration #5511

Open asa08 opened 3 months ago

asa08 commented 3 months ago

I want to use lookbehind in a custom rule but get Invalid configuration for 'xxx'. Falling back to default.. Is there any other way?

Example

No setClass on the line before the line containing configur.

(?<!setClass.*?\n.*?)configur

Highlighted

func setup() {
  configur()
}

Not Highlighted

func setup() {
  setClass()
  configur()
}

Thank you.

SimplyDanny commented 3 months ago

Lookbehind is allowed in principle, yet the documentation for NSRegularExpression states:

The length of possible strings matched by the look-behind pattern must not be unbounded (no * or + operators).

That's causing the regex to fail to be constructed. You need to look for an alternative expression.