-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Patch.replaceSymbols bug that affects ScalaTest rule. (#1293)
Previously, the ScalaTest autofix rule didn't properly handle cases with renamed imports due to a bug in Scalafix. This commit fixes that bug so that the ScalaTest rule works correctly as expected.
- Loading branch information
Showing
9 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
9 changes: 9 additions & 0 deletions
9
scalafix-tests/input/src/main/scala/org/scalatest_autofix/Matchers.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
ignore = true | ||
*/ | ||
package org.scalatest_autofix | ||
|
||
object Matchers extends Matchers | ||
class Matchers { | ||
def shouldBe(n: Int): Unit = ??? | ||
} |
10 changes: 10 additions & 0 deletions
10
scalafix-tests/input/src/main/scala/tests/scalatest_autofix/ScalatestAutofixRule.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
rule = ScalatestAutofixRule | ||
*/ | ||
package tests.scalatest_autofix | ||
|
||
import org.scalatest_autofix.Matchers._ | ||
|
||
object ScalatestAutofixRule { | ||
def foo(): Unit = shouldBe(1) | ||
} |
22 changes: 22 additions & 0 deletions
22
scalafix-tests/input/src/main/scala/tests/scalatest_autofix/ScalatestAutofixRule2.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
rule = ScalatestAutofixRule | ||
*/ | ||
package tests.scalatest_autofix | ||
|
||
import scala.collection.mutable | ||
|
||
object ScalatestAutofixRule2 { | ||
object WithRename { | ||
import org.scalatest_autofix.{Matchers => ScalaTestMatchers} | ||
|
||
class UsesRename extends ScalaTestMatchers | ||
class UsesOriginal extends org.scalatest_autofix.Matchers { | ||
val x = mutable.ListBuffer.empty[Int] | ||
} | ||
} | ||
object WithoutRename { | ||
import org.scalatest_autofix.Matchers | ||
class UsesRename extends Matchers | ||
class UsesOriginal extends org.scalatest_autofix.Matchers | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
scalafix-tests/output/src/main/scala/org/scalatest_autofix/matchers/should/Matchers.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.scalatest_autofix.matchers.should | ||
|
||
object Matchers extends Matchers | ||
class Matchers { | ||
def shouldBe(n: Int): Unit = ??? | ||
} |
7 changes: 7 additions & 0 deletions
7
scalafix-tests/output/src/main/scala/tests/scalatest_autofix/ScalatestAutofixRule.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tests.scalatest_autofix | ||
|
||
import org.scalatest_autofix.matchers.should.Matchers._ | ||
|
||
object ScalatestAutofixRule { | ||
def foo(): Unit = shouldBe(1) | ||
} |
20 changes: 20 additions & 0 deletions
20
scalafix-tests/output/src/main/scala/tests/scalatest_autofix/ScalatestAutofixRule2.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package tests.scalatest_autofix | ||
|
||
import scala.collection.mutable | ||
import org.scalatest_autofix.matchers | ||
import org.scalatest_autofix.matchers.should.Matchers | ||
|
||
object ScalatestAutofixRule2 { | ||
object WithRename { | ||
import org.scalatest_autofix.matchers.should.{Matchers => ScalaTestMatchers} | ||
|
||
class UsesRename extends ScalaTestMatchers | ||
class UsesOriginal extends matchers.should.Matchers { | ||
val x = mutable.ListBuffer.empty[Int] | ||
} | ||
} | ||
object WithoutRename { | ||
class UsesRename extends Matchers | ||
class UsesOriginal extends matchers.should.Matchers | ||
} | ||
} |
This file contains 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
12 changes: 12 additions & 0 deletions
12
scalafix-tests/unit/src/main/scala/scalafix/test/ScalatestAutofixRule.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package scalafix.test | ||
|
||
import scalafix.v1.SemanticRule | ||
import scalafix.v1._ | ||
|
||
class ScalatestAutofixRule extends SemanticRule("ScalatestAutofixRule") { | ||
override def fix(implicit doc: SemanticDocument): Patch = { | ||
Patch.replaceSymbols( | ||
"org.scalatest_autofix.Matchers" -> "org.scalatest_autofix.matchers.should.Matchers" | ||
) | ||
} | ||
} |