Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions scalafix/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ lazy val `weaver-test` = (project in file("."))
v0_8_3_tests.projectRefs ++
v0_9_0_input.projectRefs ++
v0_9_0_output.projectRefs ++
v0_9_0_tests.projectRefs: _*
v0_9_0_tests.projectRefs ++
v0_11_0_input.projectRefs ++
v0_11_0_output.projectRefs ++
v0_11_0_tests.projectRefs ++
v0_13_0_input.projectRefs ++
v0_13_0_output.projectRefs ++
v0_13_0_tests.projectRefs: _*
)
.settings(
publish / skip := true
Expand Down Expand Up @@ -59,12 +65,21 @@ lazy val v0_11_0_input =
makeInput("v0_11_0", "org.typelevel" %% "weaver-cats" % "0.10.1")
lazy val v0_11_0_output =
makeOutput("v0_11_0",
"org.typelevel" %% "weaver-cats" % "0.11-799b8e6-SNAPSHOT")
"org.typelevel" %% "weaver-cats" % "0.11.0")
lazy val v0_11_0_tests = makeTests("v0_11_0", v0_11_0_input, v0_11_0_output)

lazy val v0_13_0_input =
makeInput("v0_13_0", "org.typelevel" %% "weaver-cats" % "0.12.0")
lazy val v0_13_0_output =
makeOutput("v0_13_0",
"org.typelevel" %% "weaver-cats" % "0.13-ff3228c-SNAPSHOT")

lazy val v0_13_0_tests = makeTests("v0_13_0", v0_13_0_input, v0_13_0_output)

lazy val testsAggregate = Project("tests", file("target/testsAggregate"))
.aggregate(v0_8_3_tests.projectRefs ++ v0_9_0_tests.projectRefs ++
v0_11_0_tests.projectRefs: _*)
v0_11_0_tests.projectRefs ++
v0_13_0_tests.projectRefs: _*)
.settings(
publish / skip := true
)
Expand Down
2 changes: 1 addition & 1 deletion scalafix/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
resolvers += Resolver.sonatypeRepo("releases")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.2")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.6")
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.11.0")
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
fix.RenameAssertToExpect
fix.RewriteExpect
fix.AddClueToExpect
fix.v0_11_0
fix.v0_11_0
fix.v0_13_0
47 changes: 47 additions & 0 deletions scalafix/rules/src/main/scala/fix/v0_13_0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fix

import scalafix.v1._
import scala.meta._

class v0_13_0 extends SemanticRule("v0_13_0") {

override def fix(implicit doc: SemanticDocument): Patch =
renameMutableSuites + renameSuiteName

def renameMutableSuites(implicit doc: SemanticDocument): Patch = {
val suiteNames = Map(
"MutableIOSuite" -> "IOSuite",
"MutableFSuite" -> "FSuite",
"SimpleMutableIOSuite" -> "SimpleIOSuite",
"FunSuiteIO" -> "FunSuite"
)
suiteNames.map { case (prevSuiteName, nextSuiteName) =>
val suiteSymbol = SymbolMatcher.normalized(s"weaver/$prevSuiteName")
doc.tree.collect {
case suiteSymbol(tree) =>
tree match {
case Type.Name(`prevSuiteName`) =>
Patch.replaceTree(tree, nextSuiteName)
case Importee.Name(_) =>
Patch.replaceTree(tree, nextSuiteName)
case Importee.Rename(fromTree, _) =>
Patch.replaceTree(fromTree, nextSuiteName)
case _ =>
Patch.empty
}
}.asPatch
}.asPatch
}

def renameSuiteName(implicit doc: SemanticDocument): Patch = {
val symbol = SymbolMatcher.normalized(s"weaver/EffectSuite#name().")
doc.tree.collect {
case symbol(tree) =>
tree match {
case Term.Name("name") =>
Patch.replaceTree(tree, "suiteName")
case _ => Patch.empty
}
}.asPatch
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
rule = v0_13_0
*/
package fix

import weaver.FunSuiteIO
import cats.effect._

object BasicFunSuiteIO extends FunSuiteIO {
def basicFunction(suite: FunSuiteIO): FunSuiteIO = suite
}

import weaver.{ FunSuiteIO => FunSuiteIOAlias }

object AnotherFunSuiteIO extends FunSuiteIOAlias
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
rule = v0_13_0
*/
package fix

import weaver.MutableIOSuite
import cats.effect._

object BasicMutableIOSuite extends MutableIOSuite {

type Res = Unit
def sharedResource: Resource[IO, Res] = Resource.unit

def basicFunction(suite: MutableIOSuite): MutableIOSuite = suite
}

import weaver.{ MutableIOSuite => MutableIOSuiteAlias }

object AnotherMutableIOSuite extends MutableIOSuiteAlias {
type Res = Unit
def sharedResource: Resource[IO, Res] = Resource.unit
}

import weaver.MutableFSuite

trait BasicMutableFSuite extends MutableFSuite[IO]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
rule = v0_13_0
*/
package fix
import weaver._

object RenameNameToSuiteName extends SimpleIOSuite {

pureTest("basic") {
expect.same(name, "basic")
}

pureTest("other name") {
val name = "basic"
expect.same(name, "basic")
}

def getName(suite: SimpleIOSuite): String = {
suite.name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
rule = v0_13_0
*/
package fix

import weaver.SimpleMutableIOSuite
import cats.effect._

object BasicSimpleMutableIOSuite extends SimpleMutableIOSuite {
def basicFunction(suite: SimpleMutableIOSuite): SimpleMutableIOSuite = suite
}

import weaver.{ SimpleMutableIOSuite => SimpleMutableIOSuiteAlias }

object AnotherSimpleMutableIOSuite extends SimpleMutableIOSuiteAlias
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fix

import weaver.FunSuite
import cats.effect._

object BasicFunSuiteIO extends FunSuite {
def basicFunction(suite: FunSuite): FunSuite = suite
}

import weaver.{ FunSuite => FunSuiteIOAlias }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: how about removing IO from the alias?

Suggested change
import weaver.{ FunSuite => FunSuiteIOAlias }
import weaver.{ FunSuite => FunSuiteAlias }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to leave it untouched. We can't guarantee what the alias name is, nor whether it will conflict with anything else in the user code.


object AnotherFunSuiteIO extends FunSuiteIOAlias
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fix

import weaver.IOSuite
import cats.effect._

object BasicMutableIOSuite extends IOSuite {

type Res = Unit
def sharedResource: Resource[IO, Res] = Resource.unit

def basicFunction(suite: IOSuite): IOSuite = suite
}

import weaver.{ IOSuite => MutableIOSuiteAlias }

object AnotherMutableIOSuite extends MutableIOSuiteAlias {
type Res = Unit
def sharedResource: Resource[IO, Res] = Resource.unit
}

import weaver.FSuite

trait BasicMutableFSuite extends FSuite[IO]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fix
import weaver._

object RenameNameToSuiteName extends SimpleIOSuite {

pureTest("basic") {
expect.same(suiteName, "basic")
}

pureTest("other name") {
val name = "basic"
expect.same(name, "basic")
}

def getName(suite: SimpleIOSuite): String = {
suite.suiteName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fix

import weaver.SimpleIOSuite
import cats.effect._

object BasicSimpleMutableIOSuite extends SimpleIOSuite {
def basicFunction(suite: SimpleIOSuite): SimpleIOSuite = suite
}

import weaver.{ SimpleIOSuite => SimpleMutableIOSuiteAlias }

object AnotherSimpleMutableIOSuite extends SimpleMutableIOSuiteAlias
8 changes: 8 additions & 0 deletions scalafix/v0_13_0/tests/src/test/scala/fix/RuleSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fix

import scalafix.testkit._
import org.scalatest.funsuite.AnyFunSuiteLike

class RuleSuite extends AbstractSemanticRuleSuite with AnyFunSuiteLike {
runAllTests()
}
Loading