Created
June 25, 2025 11:01
-
-
Save zainab-ali/a3628836af99335e2b82d0ff42d16759 to your computer and use it in GitHub Desktop.
weaver: replace `expect(.. == ..)` with `expect.same`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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