SpaceAfterIf rule generates false warning when if is the first statement in...
Brought to you by:
chrismair
The SpaceAfterIf rule generates a false warning when the first statement in a Spock feature method is an if statement. The warning message issues is:
Error from [org.codenarc.rule.formatting.SpaceAfterIfRule] processing source file [<fully-qualified-filename>]</fully-qualified-filename>
This error message is issued even though there is a single blank space following the if. This bug was found with CodeNarc version 0.21 and Groovy version 2.4.4.
The following test case can be used to reporduce this problem:
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification
class CodeNarcTestSpec extends Specification {
Project project
def setup() {
project = ProjectBuilder.builder().build()
}
def 'codeNarcTest'() {
given:
if (testVar == 'true') {
println('testing')
}
expect:
project.name == 'test'
where:
testVar << 'true'
}
}
For what it's worth, that is an error message, rather than a rule violation, so that means CodeNarc experienced an error parsing the source code. I'll take a look when I get a chance.
I was not able to reproduce with the current CodeNarc codebase (0.25.x) with either Groovy 2.1.8 or 2.4.4. There were significant Groovy-related changes in the more recent versions of CodeNarc, specifically version 0.23. I expect that upgrading CodeNarc may fix this problem.
I'm going to go ahead and close this. If anyone reproduces this with CodeNarc 0.25 or later, please reopen.