4

I am trying to failed compilation if there are any unused imports, local or private variables or dead code in the codebase. So, I have added following 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"
      )

But whenever I compile my project, it fails compilation and gives the following error.

[error] 'imports' is not a valid choice for '-Ywarn-unused'
[error] bad option: '-Ywarn-unused:imports'

scala version: 2.11.11

I am not sure what mistake i am doing.

Mahesh Chand
  • 3,158
  • 19
  • 37

1 Answers1

1

Below settings should work -

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

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

Hope this helps.

user51
  • 8,843
  • 21
  • 79
  • 158