Menu

#167 SpaceAfterIf rule generates false warning when if is the first statement in a Spock feature method

None
closed
None
5
2016-09-10
2016-06-30
No

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>]

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'
}

}

Discussion

  • Chris Mair

    Chris Mair - 2016-06-30

    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.

     
  • Chris Mair

    Chris Mair - 2016-07-03

    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.

     
  • Chris Mair

    Chris Mair - 2016-09-10

    I'm going to go ahead and close this. If anyone reproduces this with CodeNarc 0.25 or later, please reopen.

     
  • Chris Mair

    Chris Mair - 2016-09-10
    • status: open --> closed
    • assigned_to: Chris Mair
    • Group: -->
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.