Repository: scala-steward-org/scala-steward
Pull request #1915 (2021-02-01 20:43:54)

Do not wrap UrlChecker in Resource
Using `Resource` for `UrlChecker` is not necessary because
`CaffeineCache#close` is a no-op.


Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala b/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
index 6f1f54fb..68213b80 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
@@ -72,8 +72,11 @@ final class Context[F[_]](implicit
 )
 
 object Context {
-  def step0[F[_]: ConcurrentEffect: ContextShift: Parallel: Timer](
-      args: Cli.Args
+  def step0[F[_]](args: Cli.Args)(implicit
+      contextShift: ContextShift[F],
+      parallel: Parallel[F],
+      timer: Timer[F],
+      F: ConcurrentEffect[F]
   ): Resource[F, Context[F]] =
     for {
       blocker <- Blocker[F]
@@ -82,7 +85,6 @@ object Context {
       implicit0(client: Client[F]) <- OkHttpBuilder.withDefaultClient[F](blocker).map(_.create)
       implicit0(fileAlg: FileAlg[F]) = FileAlg.create[F]
       implicit0(processAlg: ProcessAlg[F]) = ProcessAlg.create[F](blocker, config.processCfg)
-      implicit0(urlChecker: UrlChecker[F]) <- UrlChecker.create[F](config)
       implicit0(workspaceAlg: WorkspaceAlg[F]) = WorkspaceAlg.create[F](config)
       context <- Resource.liftF(step1[F](config))
     } yield context
@@ -94,17 +96,17 @@ object Context {
       logger: Logger[F],
       parallel: Parallel[F],
       processAlg: ProcessAlg[F],
-      urlChecker: UrlChecker[F],
       workspaceAlg: WorkspaceAlg[F],
-      F: Sync[F]
+      F: Async[F]
   ): F[Context[F]] =
     for {
       _ <- printBanner[F]
       vcsUser <- config.vcsUser[F]
+      implicit0(artifactMigration: ArtifactMigrations) <- ArtifactMigrations.create[F](config)
       implicit0(migrationsLoader: MigrationsLoader[F]) = new MigrationsLoader[F]
       implicit0(migrationAlg: MigrationAlg) <-
         migrationsLoader.loadAll(config.scalafixCfg).map(new MigrationAlg(_))
-      implicit0(artifactMigration: ArtifactMigrations) <- ArtifactMigrations.create[F](config)
+      implicit0(urlChecker: UrlChecker[F]) <- UrlChecker.create[F](config)
       kvsPrefix = Some(config.vcsType.asString)
       pullRequestsStore <- CachingKeyValueStore.wrap(
         new JsonKeyValueStore[F, Repo, Map[Uri, PullRequestData]]("pull_requests", "2", kvsPrefix)
diff --git a/modules/core/src/main/scala/org/scalasteward/core/util/UrlChecker.scala b/modules/core/src/main/scala/org/scalasteward/core/util/UrlChecker.scala
index 9aba24d0..f16bfe5f 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/util/UrlChecker.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/util/UrlChecker.scala
@@ -16,7 +16,7 @@
 
 package org.scalasteward.core.util
 
-import cats.effect.{Async, Resource, Sync}
+import cats.effect.{Async, Sync}
 import cats.syntax.all._
 import com.github.benmanes.caffeine.cache.Caffeine
 import io.chrisdavenport.log4cats.Logger
@@ -32,7 +32,7 @@ trait UrlChecker[F[_]] {
 }
 
 object UrlChecker {
-  def buildCache[F[_]](config: Config)(implicit F: Sync[F]): F[CaffeineCache[Status]] =
+  private def buildCache[F[_]](config: Config)(implicit F: Sync[F]): F[CaffeineCache[Status]] =
     F.delay {
       val cache = Caffeine
         .newBuilder()
@@ -46,8 +46,8 @@ object UrlChecker {
       client: Client[F],
       logger: Logger[F],
       F: Async[F]
-  ): Resource[F, UrlChecker[F]] =
-    Resource.make(buildCache(config))(_.close().void).map { statusCache =>
+  ): F[UrlChecker[F]] =
+    buildCache(config).map { statusCache =>
       new UrlChecker[F] {
         override def exists(url: Uri): F[Boolean] =
           status(url).map(_ === Status.Ok).handleErrorWith { throwable =>
diff --git a/project/Dependencies.scala b/project/Dependencies.scala
index 70654be8..8afb5588 100644
--- a/project/Dependencies.scala
+++ b/project/Dependencies.scala
@@ -21,7 +21,7 @@ object Dependencies {
   val coursierCore = "io.get-coursier" %% "coursier" % "2.0.9"
   val coursierCatsInterop = "io.get-coursier" %% "coursier-cats-interop" % coursierCore.revision
   val cron4sCore = "com.github.alonsodomin.cron4s" %% "cron4s-core" % "0.6.1"
-  val disciplineMunit = "org.typelevel" %% "discipline-munit" % "1.0.5"
+  val disciplineMunit = "org.typelevel" %% "discipline-munit" % "1.0.4"
   val fs2Core = "co.fs2" %% "fs2-core" % "2.5.0"
   val fs2Io = "co.fs2" %% "fs2-io" % fs2Core.revision
   val http4sCore = "org.http4s" %% "http4s-core" % "0.21.16"
diff --git a/project/build.properties b/project/build.properties
index 0b2e09c5..d91c272d 100644
--- a/project/build.properties
+++ b/project/build.properties
@@ -1,1 +1,1 @@
-sbt.version=1.4.7
+sbt.version=1.4.6


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/mock/MockContext.scala b/modules/core/src/test/scala/org/scalasteward/core/mock/MockContext.scala
index 5ff6ce9d..4f6bb98e 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/mock/MockContext.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/mock/MockContext.scala
@@ -1,8 +1,8 @@
 package org.scalasteward.core.mock
 
 import better.files.File
+import cats.Parallel
 import cats.effect.{BracketThrow, Sync}
-import cats.{Applicative, Parallel}
 import io.chrisdavenport.log4cats.Logger
 import org.http4s.client.Client
 import org.http4s.{HttpApp, Uri}
@@ -11,7 +11,6 @@ import org.scalasteward.core.application.Cli.EnvVar
 import org.scalasteward.core.application.{Cli, Config, Context, SupportedVCS}
 import org.scalasteward.core.io._
 import org.scalasteward.core.scalafix.MigrationsLoaderTest
-import org.scalasteward.core.util.UrlChecker
 import org.scalasteward.core.vcs.data.AuthenticatedUser
 import scala.concurrent.duration._
 
@@ -41,7 +40,6 @@ object MockContext {
   implicit private val fileAlg: FileAlg[MockEff] = new MockFileAlg
   implicit private val logger: Logger[MockEff] = new MockLogger
   implicit private val processAlg: ProcessAlg[MockEff] = MockProcessAlg.create(config.processCfg)
-  implicit private val urlChecker: UrlChecker[MockEff] = _ => Applicative[MockEff].pure(false)
   implicit private val workspaceAlg: WorkspaceAlg[MockEff] = new MockWorkspaceAlg
 
   val context: Context[MockEff] =
diff --git a/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala
index e758b104..9a28cc8a 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala
@@ -23,7 +23,7 @@ class VCSExtraAlgTest extends FunSuite {
 
   implicit val client: Client[IO] = Client.fromHttpApp[IO](routes.orNotFound)
   implicit val urlChecker: UrlChecker[IO] =
-    UrlChecker.create[IO](MockContext.config).allocated.map(_._1).unsafeRunSync()
+    UrlChecker.create[IO](MockContext.config).unsafeRunSync()
 
   private val updateFoo = Update.Single("com.example" % "foo" % "0.1.0", Nel.of("0.2.0"))
   private val updateBar = Update.Single("com.example" % "bar" % "0.1.0", Nel.of("0.2.0"))