0

i am using checkstyle.

i want to configure checkstyle so that code indentation use 2 space. For example :-

while(condition) {
  if(condition) {
    while(condition)
  }
}

Please note the inentation is using 2 spaces. For example :- if block startted after 2 spaces.

i tried

     <module name="Checker">
       <module name="Indentation">
        <property name="basicOffset" value="2"/>
        <property name="caseIndent" value="2"/>
       </module>
    </module>

But it does not give warning on applying checkstyles when i add 4 spaces instead of 2 like below

 if(condition) {
        while(condition)
      }

I am not getting whats the issue?

1 Answer 1

3

Checkstyle inspects code that you have. It doesn't control formatting. You need to control the formatting through Eclipse.

Window -> Preferences -> Java -> Code Style -> Formatter

is where you want to start poking around.

EDIT after update of question:

The Indentation module belongs under the TreeWalker module, not the Checker module.

Sign up to request clarification or add additional context in comments.

5 Comments

Thats a valid point that i need to use formatting if i want to do indentation. Actually i want to display warning if somebody adds 4 spaces instead of 2 space on applying checkstyles.I updated my question.
@user3198603 Updated answer to reflect new question.
Thanks Eric.It worked could you point me to some tutorial where i can learn about these modules ?
Also if you can provide your inputs on stackoverflow.com/questions/23652606/…. It would be a help. Thanks in advance.
@user3198603 The checkstyle homepage tells all about all the modules. checkstyle.sourceforge.net/index.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.