playframeworklintscalac

Using tpolecat's recommended scalac flags with Play in Scala


Play generates scala classes from routes files, twirl templates. When I add scalac linting flags, sbt picks up generated classes making it impossible to use together with play.

I really want to use https://github.com/DavidGregory084/sbt-tpolecat all these nice linting rules to increase code quality, but I am unsure how to exclude the generated files for scalac flags.


Solution

  • I encountered the compiler warning of "Unused import" on Play Framework/Twirl templates' @(... when using the sbt-tpolecat plugin.

    I solved it by combing the sbt-tpolecat plugin with Silencer, https://github.com/ghik/silencer.

    I added sbt-tpolecat to /project/plugins.sbt

    addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.9")
    

    I added Silencer to build.sbt

    val silencerVersion = "1.4.4"
    libraryDependencies ++= Seq(
      compilerPlugin("com.github.ghik" % "silencer-plugin" % silencerVersion cross CrossVersion.full),
      "com.github.ghik" % "silencer-lib" % silencerVersion % Provided cross CrossVersion.full
    )
    

    And then importantly I filtered out the views package in build.sbt:

    scalacOptions += "-P:silencer:pathFilters=views"