在Eclipe PMD插件中,我可以引用标准规则集文件吗?

发布于 2024-10-02 01:15:23 字数 1200 浏览 0 评论 0原文

我希望我的 eclipse PMD 插件 配置能够访问相同的 标准规则集文件 作为 maven-pmd-plugin

您可以将 maven pmd 插件配置为使用一组自定义规则集,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>2.5</version>
    <configuration>
      <rulesets>
        <!-- Two rule sets that come bundled with PMD -->
        <ruleset>/rulesets/braces.xml</ruleset>
        <ruleset>/rulesets/naming.xml</ruleset>
        <!-- Custom local file system rule set -->
        <ruleset>d:\rulesets\strings.xml</ruleset>
        <!-- Custom remote rule set accessed via a URL -->
        <ruleset>http://localhost/design.xml</ruleset>
      </rulesets>
    </configuration>
</plugin>

但在 eclipse 插件中您只能打开/关闭单个规则或指定单个规则集文件。规则集文件是否可以包含其他几个规则集文件?或者我是否必须从我想要使用的规则集中自动聚合该文件?

I would like my eclipse PMD plugin configuration to access the same standard ruleset files as the maven-pmd-plugin.

You can configure the maven pmd plugin to use a custom set of rule sets like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>2.5</version>
    <configuration>
      <rulesets>
        <!-- Two rule sets that come bundled with PMD -->
        <ruleset>/rulesets/braces.xml</ruleset>
        <ruleset>/rulesets/naming.xml</ruleset>
        <!-- Custom local file system rule set -->
        <ruleset>d:\rulesets\strings.xml</ruleset>
        <!-- Custom remote rule set accessed via a URL -->
        <ruleset>http://localhost/design.xml</ruleset>
      </rulesets>
    </configuration>
</plugin>

but in the eclipse plugin you can only switch on / turn off individual rules or specify a single ruleset file. Is there perhaps a way that ruleset file can include several others? Or do I have to aggregate that file automatically from the rulesets I want to use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若沐 2024-10-09 01:15:23

您可以在 PMD 规则集文件中包含其他规则集,例如,

<ruleset ...>
    ...
    <rule ref="rulesets/basic.xml"/>
    ...
    <rule ref="rulesets/strings.xml">
        <exclude name="AvoidDuplicateLiterals"/>
    </rule>
    ...
</ruleset>

这实际上是我们自己的规则集文件的摘录,因此它被证明是有效的:-)

如您所见,您可以从规则集中排除/包含单个规则,甚至重新配置它们。需要注意的是:不得在单个规则集中混合不同语言的规则。即在我们的例子中,我们必须为 Java 和 JSP 创建单独的规则集。

我自己从此页面学到了这些技巧。

You can include other rulesets in a PMD ruleset file, e.g.

<ruleset ...>
    ...
    <rule ref="rulesets/basic.xml"/>
    ...
    <rule ref="rulesets/strings.xml">
        <exclude name="AvoidDuplicateLiterals"/>
    </rule>
    ...
</ruleset>

This is actually an excerpt from our own ruleset file, so it is proven to work :-)

As you can see, you can exclude/include individual rules from your ruleset, or even reconfigure them. One caveat: you must not mix rules for different languages in a single ruleset. I.e. in our case, we had to create separate rulesets for Java and JSP.

I learned the tricks myself from this page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文