Mahesh Chand
Mahesh Chand

Reputation: 3250

How to failed compilation if there are any dead code or unused imports, variables etc

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.

Upvotes: 4

Views: 1159

Answers (1)

user51
user51

Reputation: 10143

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.

Upvotes: 1

Related Questions