Skip to content

Instantly share code, notes, and snippets.

@zainab-ali
Created June 25, 2025 11:01
Show Gist options
  • Select an option

  • Save zainab-ali/a3628836af99335e2b82d0ff42d16759 to your computer and use it in GitHub Desktop.

Select an option

Save zainab-ali/a3628836af99335e2b82d0ff42d16759 to your computer and use it in GitHub Desktop.
weaver: replace `expect(.. == ..)` with `expect.same`
package fix
import scalafix.v1._
import scala.meta._
class RenameExpectToExpectSame extends SemanticRule("RenameExpectToExpectSame") {
override def fix(implicit doc: SemanticDocument): Patch = {
val expectMethod =
SymbolMatcher.normalized("weaver/Expectations.Helpers#expect.")
doc.tree.collect {
case expectMethod(tree) =>
val equalities = tree.collect {
case [email protected](lhs, Term.Name("=="), _, List(rhs)) => (lhs, rhs)
}
equalities match {
case (lhs, rhs) :: Nil => Patch.replaceTree(tree, s"expect.same($lhs, $rhs)")
case _ => Patch.empty
}
}.asPatch
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment