Open leojosefm opened 5 years ago
It took a little head scratching but I now see that pattern isn't working for you. The SimpleTextMatchCheck evaluates the regex against each line of the file individually. It uses "java.io.LineNumberReader.readLine()" to grab each line's text. The problem is that this method doesn't return the newline so the string that's being compared doesn't contain the newline that your expression wants. This seems like a bug so I'll leave this issue open for now as a reminder to address it at some point.
I think I see an alternative solution that'll work better for you and won't require you to wait for a patched version of the plugin. Try this pattern but plug it into the multiline check type:
(?i)EXIT\s+SCRIPT\s*\n*(?=[\w])
As you'll see if you plug this expression into https://regex101.com/ this looks for occurrences of "EXIT SCRIPT" that are not the last "word character" in the file. It still considers the final occurrence of that string in the file to not be a match even if it is followed by combinations of trailing spaces and empty lines.
I've created a unit test on line 73 of this file to verify that this pattern works with this plugin.
I'm using below regex to find occurance of command EXIT SCRIPT except for last line. However it is not wokring
(?i)(EXIT\s+SCRIPT.*$)(\n)
Working:
(?i)(EXIT\s+SCRIPT.*$)
It's working when used without \n . But I want to capture the code smell only if it not in last line of the file.