Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafix to the latest version, fix some rules and run the tests in the CI #2415

Merged
merged 20 commits into from
Jun 28, 2021
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ jobs:

- run: sbt --client '++${{ matrix.scala }}; fmtCheck; test; mimaReportBinaryIssues'

- name: Scalafix tests
if: matrix.scala == '2.13.6'
run: |
cd scalafix
sbt testCI

- if: matrix.scala == '2.13.6'
run: sbt --client '++${{ matrix.scala }}; microsite/mdoc'

Expand Down
11 changes: 9 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ ThisBuild / organizationName := "Functional Streams for Scala"
ThisBuild / homepage := Some(url("https://github.com/typelevel/fs2"))
ThisBuild / startYear := Some(2013)

ThisBuild / crossScalaVersions := Seq("3.0.0", "2.12.14", "2.13.6")
val NewScala = "2.13.6"

ThisBuild / crossScalaVersions := Seq("3.0.0", "2.12.14", NewScala)

ThisBuild / githubWorkflowJavaVersions := Seq("[email protected]")

Expand All @@ -28,8 +30,13 @@ ThisBuild / spiewakCiReleaseSnapshots := true
ThisBuild / spiewakMainBranches := List("main", "series/2.5.x")

ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("fmtCheck", "test", "mimaReportBinaryIssues"))
WorkflowStep.Sbt(List("fmtCheck", "test", "mimaReportBinaryIssues")),
// WorkflowStep.Sbt(List("coreJVM/it:test")) // Memory leak tests fail intermittently on CI
WorkflowStep.Run(
List("cd scalafix", "sbt testCI"),
name = Some("Scalafix tests"),
cond = Some(s"matrix.scala == '$NewScala'")
)
)

ThisBuild / scmInfo := Some(
Expand Down
1 change: 0 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.6")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.21")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29")
33 changes: 19 additions & 14 deletions scalafix/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,51 @@ inThisBuild(
),
scalaVersion := V.scala212,
addCompilerPlugin(scalafixSemanticdb),
scalacOptions ++= List(
"-Yrangepos"
)
scalacOptions ++= List("-Yrangepos")
)
)

skip in publish := true
publish / skip := true

lazy val rules = project.settings(
moduleName := "scalafix",
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % V.scalafixVersion
)

lazy val input = project.settings(
skip in publish := true,
publish / skip := true,
libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % "0.10.6",
"com.typesafe.akka" %% "akka-stream" % "2.5.21"
)
)

lazy val output = project.settings(
skip in publish := true,
publish / skip := true,
libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % "1.0.0"
"co.fs2" %% "fs2-core" % "1.0.0",
"com.typesafe.akka" %% "akka-stream" % "2.5.21"
)
)

lazy val tests = project
.settings(
skip in publish := true,
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.scalafixVersion % Test cross CrossVersion.full,
compile.in(Compile) :=
compile.in(Compile).dependsOn(compile.in(input, Compile)).value,
publish / skip := true,
libraryDependencies += ("ch.epfl.scala" % "scalafix-testkit" % V.scalafixVersion % Test)
.cross(CrossVersion.full),
Compile / compile :=
(Compile / compile).dependsOn(input / Compile / compile).value,
scalafixTestkitOutputSourceDirectories :=
sourceDirectories.in(output, Compile).value,
(output / Compile / sourceDirectories).value,
scalafixTestkitInputSourceDirectories :=
sourceDirectories.in(input, Compile).value,
(input / Compile / sourceDirectories).value,
scalafixTestkitInputClasspath :=
fullClasspath.in(input, Compile).value,
(input / Compile / fullClasspath).value
)
.dependsOn(rules)
.enablePlugins(ScalafixTestkitPlugin)

addCommandAlias(
"testCI",
"; set (output / Compile / compile / skip) := true; test; set (output / Compile / compile / skip) := false;"
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import fs2.async.{Ref, refOf, _}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

abstract class ConcurrentDataTypes[F[_]: Effect] {
abstract class ConcurrentDataTypes[F[_]: ConcurrentEffect: Timer] {
// Ref
val ref: F[Ref[F, Int]] = Ref(1)
refOf[F, Int](1)
Expand Down
2 changes: 1 addition & 1 deletion scalafix/input/src/main/scala/fix/Scheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fs2._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

abstract class SchedulerTimer[F[_]: Effect] {
abstract class SchedulerTimer[F[_]: ConcurrentEffect: Timer] {

val scheduler: Scheduler
val duration = 1.second
Expand Down
3 changes: 2 additions & 1 deletion scalafix/input/src/main/scala/fix/Usability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ rule = v1
*/
package fix

import cats.effect.IO
import cats.effect.{Concurrent, IO}
import fs2._
import scala.concurrent.ExecutionContext.Implicits.global

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

val observe1 = s.observe1(_ => IO.unit)
Expand Down
5 changes: 3 additions & 2 deletions scalafix/output/src/main/scala/fix/ConcurrentDataTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import cats.effect.concurrent
import cats.effect.concurrent.{ Deferred, Ref, Semaphore }
import cats.effect.syntax.concurrent._
import fs2.concurrent.{ Signal, SignallingRef }

abstract class ConcurrentDataTypes[F[_]: Effect] {
abstract class ConcurrentDataTypes[F[_]: ConcurrentEffect: Timer] {
// Ref
val ref: F[Ref[F, Int]] = Ref.of(1)
Ref.of[F, Int](1)
Expand All @@ -31,7 +32,7 @@ abstract class ConcurrentDataTypes[F[_]: Effect] {
val f2: F[Deferred[F, Int]] = promise
e.map(_.get)
def scheduler: Timer[F]
e.map(_.timeout(1.second))
e.map(_.get.timeout(1.second))

// Semaphore
val s: F[concurrent.Semaphore[F]] = cats.effect.concurrent.Semaphore(1)
Expand Down
2 changes: 1 addition & 1 deletion scalafix/output/src/main/scala/fix/Scheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs2._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

abstract class SchedulerTimer[F[_]: Effect] {
abstract class SchedulerTimer[F[_]: ConcurrentEffect: Timer] {

val scheduler: Timer[F]
val duration = 1.second
Expand Down
3 changes: 2 additions & 1 deletion scalafix/output/src/main/scala/fix/Usability.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package fix

import cats.effect.IO
import cats.effect.{Concurrent, IO}
import fs2._
import scala.concurrent.ExecutionContext.Implicits.global

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

val observe1 = s.evalTap(_ => IO.unit)
Expand Down
2 changes: 1 addition & 1 deletion scalafix/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.2.6
sbt.version=1.5.3
3 changes: 1 addition & 2 deletions scalafix/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
resolvers += Resolver.sonatypeRepo("releases")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29")
4 changes: 2 additions & 2 deletions scalafix/rules/src/main/scala/fix/v1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ object ConcurrentDataTypesRules {
case cancellableGetMatcher(Term.Select(_, s)) =>
Patch.replaceTree(s, "get")
case timedGetMatcher(s @ Term.Apply(Term.Select(pre, Term.Name("timedGet")), List(d, _))) =>
Patch.replaceTree(s, s"${pre}.timeout($d)")
Patch.replaceTree(s, s"${pre}.get.timeout($d)") + Patch.addGlobalImport(importer"cats.effect.syntax.concurrent._")

// Signal
case t @ immutableSignalMatcher(_: Term.Name) =>
Expand Down Expand Up @@ -391,7 +391,7 @@ object StreamAppRules {
tpl.copy(
inits = tpl.inits :+ Init(Type.Name("IOApp"), Name("IOApp"), List()),
stats = addProgramRun(tpl.stats)).toString()
)
) + Patch.addLeft(tpl, "extends ")

private[this] def replaceStats(stats: List[Stat]): List[Patch] =
stats.flatMap{
Expand Down
5 changes: 3 additions & 2 deletions scalafix/tests/src/test/scala/fix/RuleSuite.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fix

import scalafix.testkit.SemanticRuleSuite
import org.scalatest.FunSuiteLike
import scalafix.testkit.AbstractSemanticRuleSuite

class RuleSuite extends SemanticRuleSuite() {
class RuleSuite extends AbstractSemanticRuleSuite with FunSuiteLike {
runAllTests()
}