Eduardo Vendruscolo
Eduardo Vendruscolo

Reputation: 47

Checkstyle validation fail when needs multiple lines

I need to perform a validation rule on eclipse checkstyle, after a key { of method and before end key } should have a empty line, example:

public void wrongMethod() {
    System.out.println("wrong method");
}

correct

public void correctMethod() {

    System.out.println("correct method");

}    

I try to use a RegexpMultiline in checkstyle rules xml file, doing some like this:

<module name="RegexpMultiline">
    <property name="format" value=".+\{\n.+[;]"/>
    <property name="message" value="should have empty line"/>
</module>  

sure, this Regex expression can be better, the issue is, the multiline behavior works in a regex simulator site with the examples above, but in checkstyle dont. I search on a checkstyle documentation and not found a ready reature for this.

Anyone know a solution for this issue?

thanks.

Upvotes: 0

Views: 518

Answers (1)

Michal Kordas
Michal Kordas

Reputation: 10925

Probably you run the check on files with CRLF line endings. If yes, then remember about \r in your pattern.

This works for me:

<module name="RegexpMultiline">
    <property name="format" value="\{[\r]?\n(?![\r]?\n)"/>
    <property name="message" value="should have empty line"/>
</module>  

I've changed couple of things in the pattern:

Upvotes: 1

Related Questions