【问题标题】:How to configure `sbt` to not display warnings "Warning private default argument in object * is never used"如何将`sbt`配置为不显示警告“警告对象*中的私有默认参数从未使用”
【发布时间】:2021-03-12 07:19:11
【问题描述】:

我有一个 scala 编译器 2.12.11,编译器会打印一些警告,例如:
private default argument in class SomeClass is never used 在使用时。

我见过Scala 2.12.2 emits a ton of useless "Warning: parameter value ... in method ... is never used" warnings. How to get rid of them?,但它对我没有帮助,因为不可能否定params
你能帮我取消这个警告,但保存另一个unused 警告吗?目前,我有-Xlint 选项。

【问题讨论】:

  • 你能分享你的build.sbt 和一段代码来重现它吗?

标签: scala sbt warnings compiler-warnings


【解决方案1】:

您可以手动打开特定选项,而不是批处理-Xlint。在 2.13 中,我可以打印这样的可用选项:

scalac -Xlint:help
Enable recommended warnings
  adapted-args            An argument list was modified to match the receiver.
  nullary-unit            `def f: Unit` looks like an accessor; add parens to look side-effecting.
  inaccessible            Warn about inaccessible types in method signatures.
  infer-any               A type argument was inferred as Any.
  missing-interpolator    A string literal appears to be missing an interpolator id.
  doc-detached            When running scaladoc, warn if a doc comment is discarded.
  private-shadow          A private field (or class parameter) shadows a superclass field.
  type-parameter-shadow   A local type parameter shadows a type already in scope.
  poly-implicit-overload  Parameterized overloaded implicit methods are not visible as view bounds.
  option-implicit         Option.apply used an implicit view.
  delayedinit-select      Selecting member of DelayedInit.
  package-object-classes  Class or object defined in package object.
  stars-align             In a pattern, a sequence wildcard `_*` should match all of a repeated parameter.
  strict-unsealed-patmat  Pattern match on an unsealed class without a catch-all.
  constant                Evaluation of a constant arithmetic expression resulted in an error.
  unused                  Enable -Wunused:imports,privates,locals,implicits,nowarn.
  nonlocal-return         A return statement used an exception for flow control.
  implicit-not-found      Check @implicitNotFound and @implicitAmbiguous messages.
  serial                  @SerialVersionUID on traits and non-serializable classes.
  valpattern              Enable pattern checks in val definitions.
  eta-zero                Usage `f` of parameterless `def f()` resulted in eta-expansion, not empty application `f()`.
  eta-sam                 The Java-defined target interface for eta-expansion was not annotated @FunctionalInterface.
  deprecation             Enable -deprecation and also check @deprecated annotations.
  byname-implicit         Block adapted by implicit with by-name parameter.
  recurse-with-default    Recursive call used default argument.
  unit-special            Warn for specialization of Unit in parameter position.
  multiarg-infix          Infix operator was defined or used with multiarg operand.
  implicit-recursion      Implicit resolves to an enclosing definition.
Default: All choices are enabled by default.

所以我可以例如启用-Xlint:inaccessible -Xlint:adapted-args -Wunused:privates,locales 或我想要的任何东西,而不是一切。对于 2.12,这个列表会有所不同。 (也可以查看scalac -Xscalac -Yscalac -W)。

另一种方法是在您有意识地“破坏”某些内容时启用警告并抑制它们。对于未使用的,您有 @scala.annotation.unused,对于 2.12 和之前的其他警告,有 silencer 插件,从 2.13 开始有 @scala.annotation.nowarn 注释。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多