【问题标题】:Eclipse Code Formatter indents with double amount of spaces - Intellij IDEEclipse Code Formatter 缩进双倍空格 - Intellij IDE
【发布时间】:2017-03-06 09:58:36
【问题描述】:

我已将 Eclipse Code Formatter 配置为缩进 4 个空格,但在运行代码格式化程序后,我得到了两倍的空格。

当我使用 Intellij 的标准设置缩进时,我得到了正确数量的空格。

Checkstyle 规则:

<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 代码格式化程序:

<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"/>

IDE 的设置:

运行代码格式化程序后,什么会导致缩进的两倍?

【问题讨论】:

  • 如果这个问题是关于 Eclipse 的,请从标题和标签中删除 IntelliJ。
  • 这个问题是关于在 Intellij IDE 中使用 Eclipse Code Formatter
  • 因为在我们的团队中,我们有一些使用 Intellij 的开发人员和其他使用 Eclipse 的开发人员。我们需要可以在两个 IDE 中使用的代码格式化程序。问题是Eclipse Code Formatter的这个设置没有将缩进更改为4个空格而是8个。这个错误也被checkstyle检测到。
  • 对不起,如果我在你的团队中,我会正确使用 IntelliJ 而忽略其余部分。
  • 多么无知的回应。如果团队需要相同的代码风格,那么插件是唯一的方法。

标签: java eclipse intellij-idea code-formatting


【解决方案1】:

我在 Eclipse 代码格式化程序中遇到了相同的“连续缩进”行为,空格数量从 4 个翻倍到 8 个。我的 Eclipse 代码格式化程序文件有以下几行:

<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"/>

“continuation_indentation”的最后一行设置为 2,这让我得出结论,这可能是 2 的因数(4 x 2 = 8,对 ?)。我将值更改为“1”并且它起作用了。也许这有帮助。

顺便说一句。我在 Intellij 中的设置和你的一样

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多