gpt4 book ai didi

scala - 编译器选项警告与 linter

转载 作者:行者123 更新时间:2023-12-02 20:42:20 26 4
gpt4 key购买 nike

在 Scala 2.12 中,这些选项之间有什么区别吗:

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

如果不是,使用哪个更有意义?我还使用 fatal-warnings 和几乎所有的 -Ywarn-Xlint 选项进行编译。

最佳答案

如果你运行 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 标志之外的所有内容。

关于scala - 编译器选项警告与 linter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45676832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com