gpt4 book ai didi

scala - 如果有任何死代码或未使用的导入、变量等,如何编译失败

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

如果代码库中有任何未使用的导入、本地或私有(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/

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