【问题标题】:How to suppress Scalastyle warning?如何抑制 Scalastyle 警告?
【发布时间】:2014-02-21 10:17:06
【问题描述】:

我得到以下代码:

    string match {
      case Regex(_, "1", "0", _, _)    =>
      case Regex(_, "1", "1", null, _) =>
    }

Scalastyle 抱怨这里无法避免使用 null。 有什么办法可以仅针对这一行禁止警告?

【问题讨论】:

    标签: scalastyle


    【解决方案1】:

    Scalastyle 理解抑制 cmets:

    // scalastyle:off <rule id>
    ...
    // scalastyle:on <rule id>
    

    已列出规则 ID here

    在你的情况下,id 只是空:

    // scalastyle:off null
    ...
    // scalastyle:on null
    

    mailing list 也回答了这个问题

    【讨论】:

      【解决方案2】:

      对于单行,您只需将// scalastyle:ignore &lt;rule-id&gt; 附加到末尾,如下所示:

      string match {
        case Regex(_, "1", "0", _, _)    =>
        case Regex(_, "1", "1", null, _) => // scalastyle:ignore null
      }
      

      如果您希望 Scalastyle 忽略的内容很明显,您可以通过省略 rule-id 来禁用对当前行的所有检查(对于开/关 cmets 也可以):

      string match {
        case Regex(_, "1", "0", _, _)    =>
        case Regex(_, "1", "1", null, _) => // scalastyle:ignore
      }
      

      【讨论】:

        【解决方案3】:

        您也可以添加一个

        scalastyle_config.xml
        

        到您的项目,并启用/禁用任何规则。见http://www.scalastyle.org/configuration.html

        【讨论】: