Skip to content

Instantly share code, notes, and snippets.

@jgogstad
Last active November 16, 2020 11:30
Show Gist options
  • Save jgogstad/65348295e92f22581f40e2bcde437fea to your computer and use it in GitHub Desktop.
Save jgogstad/65348295e92f22581f40e2bcde437fea to your computer and use it in GitHub Desktop.
Disable unused scalac linters only in IntelliJ

sbt-tpolecat IntelliJ exemptions

This plugin lets you enforce strict linting rules and iterate quickly in IntelliJ at the same time.

Configure your build with sbt-tpolecat to prevent unused imports, unused parameters etc. to reach main. Adding the plugin below causes the following behavior:

  • All linters are enforced in sbt
  • The -Wunused:* flags are not enforced in IntelliJ
// File: ~/.sbt/1.0/plugins/DisableLintersIntelliJ.scala
package localsbt

import sbt.{AutoPlugin, Def, Plugins}
import sbt.Keys._
import sbt.plugins.JvmPlugin

import scala.util.Try

object DisableLintersIntelliJ extends AutoPlugin {
  override def trigger  = allRequirements
  override def requires = {
    Try(Class.forName("io.github.davidgregory084.TpolecatPlugin$"))
      .map(_.asInstanceOf[Plugins])
      .getOrElse(JvmPlugin)
  }

  override def projectSettings: Seq[Def.Setting[_]] = Seq(
    scalacOptions --= {
      if (System.getProperty("idea.managed") == "true")
        Seq(
          "-Wunused:implicits",
          "-Wunused:explicits",
          "-Wunused:imports",
          "-Wunused:locals",
          "-Wunused:params",
          "-Wunused:patvars",
          "-Wunused:privates"
        ) else Seq.empty
    }
  )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment