如何在CheckStyle中抑制警告? [英] How do I Suppress Warnings in CheckStyle?

查看:1479
本文介绍了如何在CheckStyle中抑制警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse的CheckStyle插件。

I'm using the CheckStyle plugin for Eclipse.

很高兴找到我没有打算99%的时间,但是1%的时间我实际上打算故意违反规则,我想让CheckStyle知道它不需要关注自己的标志警告。

It's great at finding things I didn't intend 99% of the time, but the 1% of the time I actually did intend to knowingly violate a rule, I would like to let CheckStyle know it need not concern itself with flagging a warning.

示例:缺少Javadoc注释规则。大多数时间我想要Javadoc对我的方法的评论。然而,一种方法如:

Example: the Missing a Javadoc comment rule. Most of the time I want Javadoc comments on my methods. However, a method such as:

public boolean isValid() {
  return valid;
}

可能没有一个。

有没有什么像 @SuppressWarnings 注释,可用于标记特定的CheckStyle规则违规是可接受的?某种特殊格式的评论可能吗?我不想禁用规则,我只是想忽略一个特定的违规。

Is there anything like the @SuppressWarnings annotation which can be used to flag a specific CheckStyle rule violation as acceptable? Some sort of specially formatted comment, maybe? I don't want to disable the rule, I just want to ignore a specific violation.

(我意识到在这种情况下我可以写Javadoc注释,但在固定规则违规的其他情况并不那么简单)

(I realize in this case I could just write the Javadoc comment, but in other cases fixing the rule violation isn't so simple).

推荐答案

似乎很简单,但需要明确的XML配置忽略它。您可以通过使用Eclipse或Netbeans的Checkstyle插件来找到GUI。我发现的例子是Checkstyle 配置页面。

Seems pretty tedious but there needs to be explicit XML configuration to ignore it. You can probably find a GUI to do it via using the Checkstyle plugin for Eclipse or Netbeans. The example I've found is on the Checkstyle configuration page.

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
    "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
    <suppress checks="JavadocStyleCheck"
              files="AbstractComplexityCheck.java"
              lines="82,108-122"/>
    <suppress checks="MagicNumberCheck"
              files="JavadocStyleCheck.java"
              lines="221"/>
</suppressions>

这篇关于如何在CheckStyle中抑制警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆