Want to enforce space between class and brace

8 views
Skip to first unread message

Andreas Jonsson

unread,
Oct 20, 2015, 9:07:54 AM10/20/15
to checkstyle
Hi,

With my current Checkstyle configuration (very similar to Google's) i'm unable to catch the following case:

public class TestClass extends SomeClass{


but it warns when i do (Whitespace Around: WhitespaceAround: '{' is not preceded with whitespace.):


public String toString(){


Is this a bug or what configuration am I missing?


Regards

Andreas

Roman Ivanov

unread,
Oct 24, 2015, 7:49:00 AM10/24/15
to Andreas Jonsson, checkstyle
Hi Andreas,

You need to share exact file and exact config and exact version checkstyle.

Here is your case, all works as expected:

04:46 /var/tmp $ java -jar checkstyle-6.11.2-all.jar -c 3.xml 3.java
Starting audit...
/var/tmp/3.java:1:41: error: '{' is not preceded with whitespace.
/var/tmp/3.java:3:25: error: '{' is not preceded with whitespace.
Audit done.
Checkstyle ends with 2 errors.

04:46 /var/tmp $ cat 3.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
<module name="Checker">
    <module name="TreeWalker">
        <module name="WhitespaceAround" />
    </module>
</module>

04:46 /var/tmp $ cat 3.java 
public class TestClass extends SomeClass{

public String toString(){
}

}
04:46 /var/tmp $ 



thanks,
Roman Ivanov

Andreas Jonsson

unread,
Oct 28, 2015, 10:25:34 AM10/28/15
to checkstyle, anj...@gmail.com
Hi Roman,

Thanks for your answer. We are using 6.11.2, here's my code & configuration (attached):

public class CheckstyleTest{ // Doesn't warn - incorrect

 
private static final int SOMETHING = 1;

 
public CheckstyleTest(){ //warns here - correct

 
System.out.println("CheckstyleTest " + SOMETHING);

 
}


 
public void test1() { // Doesn't warn - correct

 
if (3 > 2) { // Doesn't warn - correct

 
System.out.println("test1");

 
}

 
}


 
public void test2(){ //warns here - correct

 
if (3 > 2){ //warns here - correct

 
System.out.println("test2");

 
}

 
}


}


Looking forward to your answer,
Andreas
checkstyle.xml

Roman Ivanov

unread,
Oct 30, 2015, 3:41:33 PM10/30/15
to Andreas Jonsson, checkstyle

--
You received this message because you are subscribed to the Google Groups "checkstyle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to checkstyle+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages