编译器选项警告vs linter

时间:2017-08-14 14:28:15

标签: scala

在Scala 2.12中,这些选项之间存在任何差异:

  • -Xlint:adapted-args vs -Ywarn-adapted-args
  • -Xlint:nullary-unit vs -Ywarn-nullary-unit
  • -Xlint:inaccessible vs -Ywarn-inaccessible
  • -Xlint:nullary-override vs -Ywarn-nullary-override
  • -Xlint:infer-any vs -Ywarn-infer-any

如果没有,哪一个使用更有意义?我还使用fatal-warnings以及几乎所有-Ywarn-Xlint选项进行编译。

1 个答案:

答案 0 :(得分:3)

如果您运行scalac -Xlint:help,您将会看到

❯ scalac -Xlint:help
Enable or disable specific warnings
  adapted-args               Warn if an argument list is modified to match the receiver.
  nullary-unit               Warn when nullary methods return Unit.
  inaccessible               Warn about inaccessible types in method signatures.
  nullary-override           Warn when non-nullary `def f()' overrides nullary `def f'.
  infer-any                  Warn when a type argument is inferred to be `Any`.
  missing-interpolator       A string literal appears to be missing an interpolator id.
  doc-detached               A Scaladoc comment appears to be detached from its element.
  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 viewbounds.
  option-implicit            Option.apply used implicit view.
  delayedinit-select         Selecting member of DelayedInit.
  by-name-right-associative  By-name parameter of right associative operator.
  package-object-classes     Class or object defined in package object.
  unsound-match              Pattern match may not be typesafe.
  stars-align                Pattern sequence wildcard must align with sequence component.
  constant                   Evaluation of a constant arithmetic expression results in an error.
  unused                     Enable -Ywarn-unused:imports,privates,locals,implicits.
Default: All choices are enabled by default.

所以在选择Xlint选项或直接使用相应的标志之间没有区别。我会选择-Xlint(没有选项,因此默认情况下全部启用)并删除我不需要的选项,例如

-Xlint:-unused,_

启用unused标记以外的所有内容。