Skip to content

Commit

Permalink
Added usability renames
Browse files Browse the repository at this point in the history
  • Loading branch information
amarrella committed Nov 15, 2018
1 parent 209cea3 commit c1dd4c0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
16 changes: 16 additions & 0 deletions scalafix/input/src/main/scala/fix/Usability.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
rule = v1
*/
package fix

import cats.effect.IO
import fs2._
import scala.concurrent.ExecutionContext.Implicits.global

trait Usability {
def s: Stream[IO, String]

val observe1 = s.observe1(_ => IO.unit)
val join = Stream.emit(s).join(1)
val joinUnbounded = Stream.emit(s).joinUnbounded
}
14 changes: 14 additions & 0 deletions scalafix/output/src/main/scala/fix/Usability.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fix

import cats.effect.IO
import fs2._
import scala.concurrent.ExecutionContext.Implicits.global

trait Usability {
def s: Stream[IO, String]

val observe1 = s.evalTap(_ => IO.unit)
val join = Stream.emit(s).parJoin(1)
val joinUnbounded = Stream.emit(s).parJoinUnbounded
}

19 changes: 18 additions & 1 deletion scalafix/rules/src/main/scala/fix/v1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fixUtils._
class v1 extends SemanticRule("v1") {
override def fix(implicit doc: SemanticDocument): Patch =
(StreamAppRules(doc.tree) ++ SchedulerRules(doc.tree) ++ BracketRules(doc.tree) ++ ConcurrentDataTypesRules(
doc.tree) ++ ChunkRules(doc.tree)).asPatch
doc.tree) ++ ChunkRules(doc.tree) ++ UsabilityRenameRules(doc.tree)).asPatch
}

object fixUtils {
Expand Down Expand Up @@ -492,4 +492,21 @@ object ChunkRules {
val pullOutputMatcher = SymbolMatcher.normalized("fs2/Pull#outputChunk.")
val segmentMatcher = SymbolMatcher.normalized("fs2/Segment.")

}

object UsabilityRenameRules {
def apply(t: Tree)(implicit doc: SemanticDocument): List[Patch] =
t.collect {
case t @ observeMatcher(_: Term.Name) =>
Patch.replaceTree(t, "evalTap")
case t @ joinMatcher(_: Term.Name) =>
Patch.replaceTree(t, "parJoin")
case t @ joinUnboundedMatcher(_: Term.Name) =>
Patch.replaceTree(t, "parJoinUnbounded")
}

val observeMatcher = SymbolMatcher.normalized("fs2/Stream.InvariantOps#observe1.")
val joinMatcher = SymbolMatcher.normalized("fs2/Stream.PureOps#join.")
val joinUnboundedMatcher = SymbolMatcher.normalized("fs2/Stream.PureOps#joinUnbounded.")

}

0 comments on commit c1dd4c0

Please sign in to comment.