1

I'm writing custom code static analysis rules.

I want to find such override functions, which don't have super function call.

For example, regexp should find this:

override func testFunc(num: Int) {
   print()
}

But, do not find this:

override func testFunc(num: Int) {
   print()
   super.testFunc(num: num)
   print()
}

We should keep in mind that function can contain extra block inside. So, we have also not find this:

override func testFunc(num: Int) {
   print()
   super.testFunc(num: num)
   let block = {
       print("inside block")
   }
   print()
}

And we should not be interested in super function call inside blocks. Only inside that function.

I wrote this: override func\s(\w*)\(.*?\{.*?super\.\1.*?\}

But it is not consider blocks and it find functions where is super function call. And I don't know how to invert this.

  • Are you already parsing this code? The solution to your problem will be easier if you can traverse the parse tree instead. – Code-Apprentice Apr 29 '17 at 07:34
  • [This is not a job for regex.](http://stackoverflow.com/questions/546433/regular-expression-to-match-outer-brackets) – Pharaoh Apr 29 '17 at 09:39

0 Answers0