eclipse - 是否有符合 Checkstyle 格式规则的 Eclipse "Clean Up"配置文件?

标签 eclipse checkstyle

我安装了 Checkstyle 插件并选择了 Sun Checks 配置作为默认配置。

在运行“使用 Checkstyle 检查代码”之后,我在几十个类中发现了数百个 Checkstyle 违规行为。其中许多违规行为与格式相关:尤其是空格

虽然我还没有使用过它,但我认为可以在项目上运行 Eclipse“清理”工具来解决其中的一些问题。清理工具附带一个名为“Eclipse [built-in]”的配置文件。默认设置看起来与 Checkstyle 格式化规则不匹配。

除了创建一个新的 Clean Up 配置文件并手动调整它以匹配 Checkstyle 规则之外,因为 Eclipse 允许您导入一个 Clean Up 配置文件,我想知道:

是否已经存在与 Checkstyle 规则匹配的清理配置文件 xml?

如果我可以从某个地方导入它就太好了。我试过谷歌,但没能找到。

Eclipse v4.3(开普勒)
Checkstyle 插件 v5.6.1.201306282206

最佳答案

是的,我在开始使用 SonarQube 时遇到了这个问题

有两种 xml 规则,一种用于格式化程序,一种用于源代码清理。您可以在 Eclipse 和 IntelliJ IDEA 中导入(使用插件)

它对我有用,因为它减少了我在这个 70k LOC 项目中的问题:

+-----------------+--------+-------+
|                 | Before | After |
+-----------------+--------+-------+
| Issues          | 4.306  | 2.977 |
| Blocker issues  | 0      | 0     |
| Critical issues | 257    | 257   |
| Major issues    | 2.402  | 1.994 |
| Minor issues    | 1.642  | 721   |
| Info issues     | 5      | 5     |
+-----------------+--------+-------+

这是 formatter.xmlcleanup.xml规则。 归功于此 github repo这是作者。

在 Eclipse 上自动执行此类任务的博客文章 here .它指出了一个重要的警告

Not everything can be automated

Please note that although a lot of coding standards can be applied retroactively and automatically, some violations cannot be automatically eradicated. Nonetheless, Checkstyle, Eclipse and Sonar can identify the problematic code and guide developers towards coding standard compliance.

是的,我知道您只使用了 Checkstyle,但我确信它适用,因为 SonarQube 使用 Checkstyle 来提出它的问题。

关于eclipse - 是否有符合 Checkstyle 格式规则的 Eclipse "Clean Up"配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21211586/

相关文章:

eclipse - 如何将 sbt 项目导入 Eclipse?

android - 从多个类文件运行 junit 测试用例 (Robotium)

Checkstyle 空格检查

checkstyle - Java checkstyle,魔数(Magic Number)检查

java - 尝试使用 getClassContext()[1].getName() 在 Android 上获取类名

android - 无法安装第三方APK文件

java - Eclipse Helios中有哪些新功能?

java - 清理代码会破坏二进制兼容性

checkstyle - 在 ')' 和 '{' 之间强制留白

java - 如何禁止使用带有某些注释的类