如果代码库中有任何未使用的导入,局部或 private 变量或无效代码,我将尝试使编译失败。因此,我添加了以下scalacoptions。

scalacOptions ++= Seq(
        "-encoding", "UTF-8",
        "-Xfatal-warnings",
        "-Xlint:-unused,_",
        "-Ywarn-dead-code",
        "-Ywarn-unused:imports",             // Warn if an import selector is not referenced
        "-Ywarn-unused:locals",              // Warn if a local definition is unused
        "-Ywarn-unused:patvars",             // Warn if a variable bound in a pattern is unused
        "-Ywarn-unused:privates",            // Warn if a private member is unused
        "-deprecation"
      )

但是,每当我编译我的项目时,它都会编译失败并给出以下错误。
[error] 'imports' is not a valid choice for '-Ywarn-unused'
[error] bad option: '-Ywarn-unused:imports'

Scala版本:2.11.11

我不确定自己在犯什么错误。

最佳答案

以下设置应该可以工作-

    lazy val project_name = project.in(file(".")).settings(commonSettings)

    lazy val commonSettings = reformatOnCompileSettings ++ Seq(
    scalacOptions ++= Seq(
        "-Ywarn-unused-import",
        "-language:postfixOps",
        "-Ypartial-unification"
    )
    )

希望这可以帮助。

关于scala - 如果有任何无效代码或未使用的导入,变量等,如何使编译失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55067568/

10-12 17:18
查看更多