scalafix-core

Scalafix can be used as a library to run custom rules.

// ===> build.sbt
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % "@V.stableVersion"
// (optional) Scala.js is also supported
libraryDependencies += "ch.epfl.scala" %%% "scalafix-core" % "@V.stableVersion"

Example usage of the syntactic API.

package foo.bar
import scalafix._
import scala.meta._

case object MyRule extends Rule("MyRule") {
  override def fix(ctx: RuleCtx): Patch = {
    ctx.tree.collect {
      case n: scala.meta.Name => ctx.replaceTree(n, n.syntax + "1")
    }.asPatch
  }
}

println(MyRule.Uppercase("object Hello { println('world) }"))
// object HELLO { PRINTLN('world) }

The semantic API requires a more complicated setup. Please use Giter8 template.