How to match multi Line regex in SwiftLint?

263 Views Asked by At

I am trying to flag protocols that are created with one or more function or property. To start I created some regex that matches more than one function in a protocol in regex testers. However, when I build the app with the rule, it doesn't match protocols with more than one function.

custom_rules:
  protocol_more_than_one_function:
    name: "Protocol with more than one function"
    regex: 'protocol.*{\n.*func.*\n.*func'
    message: "If you would like to create a protocol with more than one function, then cretae separate protocols with one function each, then combine them with a typealias. For example, typealias BothProtocols = firstProtocol & secondProtocol"
    severity: warning

The code I am testing it on is this:

protocol GroupedProtocol {
    func stuff()
    func stuff2()
}

I assume this is because swift lint regex isn't accepting the multiline regex arguments. What regex would accomplish this at buildtime?

1

There are 1 best solutions below

3
ScottyBlades On

I went character by character. The regex broke on the {.
I had to escape it like so: \{.

smh