-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2343 from alexandrustana/2268
Split `interruptible`
- Loading branch information
Showing
16 changed files
with
171 additions
and
20 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
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
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
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
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
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
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
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
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
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,47 @@ | ||
package fix | ||
|
||
import scalafix.v1._ | ||
|
||
import scala.meta.Token._ | ||
import scala.meta._ | ||
|
||
class v3_3_0 extends SemanticRule("v3_3_0") { | ||
override def fix(implicit doc: SemanticDocument): Patch = { | ||
val IO_M = SymbolMatcher.exact("cats/effect/IO.") | ||
val Sync_interruptible_M = SymbolMatcher.exact("cats/effect/kernel/Sync#interruptible().") | ||
|
||
val IO_S = Symbol("cats/effect/IO.") | ||
val Sync_S = Symbol("cats/effect/Sync#") | ||
|
||
doc.tree.collect { | ||
// IO.interruptible(false) -> IO.interruptible | ||
// IO.interruptible(true) -> IO.interruptibleMany | ||
case t @ q"${IO_M(_)}.interruptible(${Lit.Boolean(many)})" => | ||
replaceInterruptible(many, t, s"${IO_S.displayName}") | ||
|
||
// Sync#interruptible(false) -> Sync#interruptible | ||
// Sync#interruptible(true) -> Sync#interruptibleMany | ||
case t @ q"${Sync_interruptible_M(Term.Apply(interruptible, Lit.Boolean(many) :: _))}" => | ||
interruptible.synthetics match { | ||
case TypeApplyTree(_, TypeRef(_, symbol, _) :: _) :: _ => | ||
if (symbol.displayName == "Unit") interruptible match { | ||
case Term.Select(typeF, _) => | ||
replaceInterruptible( | ||
many, | ||
t, | ||
s"${Sync_S.displayName}[${typeF.symbol.displayName}]" | ||
) | ||
case _ => Patch.empty | ||
} | ||
else replaceInterruptible(many, t, s"${Sync_S.displayName}[${symbol.displayName}]") | ||
case _ => Patch.empty | ||
} | ||
}.asPatch | ||
} | ||
|
||
def replaceInterruptible(many: Boolean, from: Tree, to: String): Patch = | ||
if (many) | ||
Patch.replaceTree(from, s"$to.interruptibleMany") | ||
else | ||
Patch.replaceTree(from, s"$to.interruptible") | ||
} |
18 changes: 18 additions & 0 deletions
18
scalafix/v3_3_0/input/src/main/scala/fix/InterruptibleRewrites.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,18 @@ | ||
/* | ||
rule = "scala:fix.v3_3_0" | ||
*/ | ||
package fix | ||
|
||
import cats.effect.{ IO, Sync } | ||
|
||
object InterruptibleRewrites { | ||
IO.interruptible(true)(IO.unit) | ||
|
||
IO.interruptible(false)(IO.unit) | ||
|
||
Sync[IO].interruptible(true)(IO.unit) | ||
|
||
Sync[IO].interruptible(false)(IO.unit) | ||
|
||
def f[F[_]](implicit F: Sync[F]): F[Unit] = F.interruptible(true)(IO.unit) | ||
} |
15 changes: 15 additions & 0 deletions
15
scalafix/v3_3_0/output/src/main/scala/fix/InterruptibleRewrites.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,15 @@ | ||
package fix | ||
|
||
import cats.effect.{ IO, Sync } | ||
|
||
object InterruptibleRewrites { | ||
IO.interruptibleMany(IO.unit) | ||
|
||
IO.interruptible(IO.unit) | ||
|
||
Sync[IO].interruptibleMany(IO.unit) | ||
|
||
Sync[IO].interruptible(IO.unit) | ||
|
||
def f[F[_]](implicit F: Sync[F]): F[Unit] = Sync[F].interruptibleMany(IO.unit) | ||
} |
8 changes: 8 additions & 0 deletions
8
scalafix/v3_3_0/tests/src/test/scala/fix/CatsEffectTests.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,8 @@ | ||
package fix | ||
|
||
import org.scalatest.FunSuiteLike | ||
import scalafix.testkit.AbstractSemanticRuleSuite | ||
|
||
class CatsEffectTests extends AbstractSemanticRuleSuite with FunSuiteLike { | ||
runAllTests() | ||
} |
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
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
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