Scala 3 Scalafix rules

SemiAuto

Rewrite implicit derived values to scala 3 syntax. Missing a bundle/library? Please open a report it as a bug or submit a pull-request.

Configuration:

// default config
SemiAuto.bundle = [all]

// option to specify a bundle of rewrites
SemiAuto.bundle = [circe, doobie]

//Bring your own rewrites.
SemiAuto.rewrites = [
  { typeClass = "my.Decoder", derived =  "Decoder" }
  { typeClass = "my.Encoder", derived =  "Encoder" }
]

Example:

// Before
case class Person(name: String)
object Person{
  implicit val codec: Codec.AsObject[Person] = deriveEncoder
}
// After
case class Person(name: String) derives Codec.AsObject

GivenAndUsing

Rewrite implicit keywords to given and using. Please note that this rule might introduce some compile errors.

Example:

// Before
case class Message(m: String)
object Message {
  implicit show: Show[Message] = ???
}
class Printer(implicit console: Console) {
  def print[A](implicit showA: Show[A]): Unit = ???
}

//After
case class Message(m: String)
object Message {
  given show: Show[Message] = ???
}
class Printer(using console: Console) {
  def print[A](using showA: Show[A]): Unit = ???
}

PackageObjectExport

Rewrite dropped feature package objects

Example:

// Before
package foo
package object db extends doobie.syntax.AllSyntax
    with doobie.Aliases
    with doobie.postgres.free.Types {
  
  def otherUsefulMethod[A](input: String): ConnectioIO[A] = ???
  def otherUsefulMethod2[A](input: Int): ConnectioIO[A] = ???
}

//After
package foo
package db {

  def otherUsefulMethod[A](input: String): ConnectioIO[A] = ???
  def otherUsefulMethod2[A](input: Int): ConnectioIO[A] = ???

  private object dbImpl extends doobie.syntax.AllSyntax
    with doobie.Aliases
    with doobie.postgres.free.Types

  export dbImpl.*
}

DropModThis

Rewrite dropped feature this qualifier from private and protected

//Before

package foo
class Foo {
  private[this] val logger = getLogger
}

//After
package foo
class Foo {
  private val logger = getLogger
}

WildcardInitializer

Rewrite dropped feature var foo: A = _

//Before

package foo
class Foo {
 var state: Int = _
}

//After
package foo
class Foo {
  var state: Int = scala.compiletime.uninitialized
}