Issue
I have configured Eclipse Code Formatter to indent with 4 spaces but after run code formatter I'm getting double amount of spaces.
src="https://i.stack.imgur.com/xdjLl.png" alt="enter image description here">
When I indent with standard settings of Intellij I'm getting correct amount of spaces.
Checkstyle rule:
<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="4"/>
</module>
Eclipse Code Formatter:
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="4"/>
What can cause double size of indentation after run the code formatter?
Solution
I experienced the same behavior with eclipse code formatter for "continuation indents", the amount of spaces was doubled from 4 to 8. My eclipse code formatter file had these lines:
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
The last line with "continuation_indentation" was set to to 2 which led me to the conclusion this could be a factor of 2 (4 x 2 = 8, right 🙂). I changed the value to "1" and it worked. Maybe that helps.
Btw. my settings in Intellij look the same like yours
Answered By - Sebastian Forza
Answer Checked By - Terry (JavaFixing Volunteer)