From 8107cef1aefbe28a112c161dd8889b6588317e5c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 6 Sep 2023 22:09:54 +0100 Subject: [PATCH] Upgraded sbt-tpolecat and removed excludes --- build.sbt | 6 ----- project/AttributeGen.scala | 1 - project/build.properties | 2 +- project/plugins.sbt | 24 +++++++++---------- .../src/test/scala/tyrian/HttpTests.scala | 1 - .../src/test/scala/tyrian/ChromeTests.scala | 2 -- .../src/test/scala/tyrian/FirefoxTests.scala | 2 -- .../scala/tyrian/TyrianIndigoBridge.scala | 2 -- .../src/main/scala/tyrian/TyrianApp.scala | 4 ---- .../src/main/scala/tyrian/TyrianApp.scala | 8 +++---- .../js/src/main/scala/tyrian/HotReload.scala | 4 ---- .../js/src/main/scala/tyrian/Location.scala | 10 -------- tyrian/js/src/main/scala/tyrian/Routing.scala | 3 --- tyrian/js/src/main/scala/tyrian/Sub.scala | 3 ++- tyrian/js/src/main/scala/tyrian/Tyrian.scala | 9 ------- .../js/src/main/scala/tyrian/TyrianAppF.scala | 10 ++++---- .../js/src/main/scala/tyrian/http/Http.scala | 10 ++++++-- .../main/scala/tyrian/runtime/Rendering.scala | 1 - .../scala/tyrian/runtime/TyrianRuntime.scala | 9 ++++--- .../scala/tyrian/websocket/WebSocket.scala | 3 --- .../js/src/test/scala/tyrian/AttrTests.scala | 2 -- .../src/test/scala/tyrian/CmdLawsTest.scala | 3 --- .../src/test/scala/tyrian/CmdSubUtils.scala | 4 ++++ .../js/src/test/scala/tyrian/HtmlTests.scala | 2 -- .../src/test/scala/tyrian/SubLawsTest.scala | 3 --- 25 files changed, 39 insertions(+), 89 deletions(-) diff --git a/build.sbt b/build.sbt index 6f882996..506b5d76 100644 --- a/build.sbt +++ b/build.sbt @@ -20,12 +20,6 @@ lazy val scalaJsDocsVersion = "1.13.1" lazy val scalaDocsVersion = "3.3.0" lazy val indigoDocsVersion = "0.14.0" -ThisBuild / tpolecatExcludeOptions := Set( - ScalacOptions.warnNonUnitStatement, - ScalacOptions.warnValueDiscard, - ScalacOptions.warnUnusedImports -) - lazy val commonSettings: Seq[sbt.Def.Setting[_]] = Seq( version := tyrianVersion, organization := "io.indigoengine", diff --git a/project/AttributeGen.scala b/project/AttributeGen.scala index b9baf0d6..b2c35dbb 100644 --- a/project/AttributeGen.scala +++ b/project/AttributeGen.scala @@ -91,7 +91,6 @@ object AttributeGen { def template(moduleName: String, fullyQualifiedPath: String, contents: String): String = s"""package $fullyQualifiedPath | - |import tyrian.Tyrian |import tyrian.Html.* |import scala.annotation.targetName | diff --git a/project/build.properties b/project/build.properties index 52413ab7..30409871 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.3 +sbt.version=1.9.4 diff --git a/project/plugins.sbt b/project/plugins.sbt index 018a987f..df2cd5ee 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,14 +1,14 @@ -addSbtPlugin("org.xerial.sbt" %% "sbt-sonatype" % "3.9.21") -addSbtPlugin("com.github.sbt" %% "sbt-pgp" % "2.2.1") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2") -addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.4") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0") -addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.7") -addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0") -addSbtPlugin("com.github.reibitto" % "sbt-welcome" % "0.3.1") -addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") -addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4") +addSbtPlugin("org.xerial.sbt" %% "sbt-sonatype" % "3.9.21") +addSbtPlugin("com.github.sbt" %% "sbt-pgp" % "2.2.1") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2") +addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.0") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0") +addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.7") +addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0") +addSbtPlugin("com.github.reibitto" % "sbt-welcome" % "0.3.1") +addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") +addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4") libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "1.1.1" diff --git a/tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala b/tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala index f192f992..fab6aaab 100644 --- a/tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala +++ b/tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala @@ -1,7 +1,6 @@ package tyrian import cats.effect.IO -import io.circe.HCursor import io.circe.parser.* import tyrian.http.* diff --git a/tyrian-chrome-tests/src/test/scala/tyrian/ChromeTests.scala b/tyrian-chrome-tests/src/test/scala/tyrian/ChromeTests.scala index 60899b4d..4df9e1e4 100644 --- a/tyrian-chrome-tests/src/test/scala/tyrian/ChromeTests.scala +++ b/tyrian-chrome-tests/src/test/scala/tyrian/ChromeTests.scala @@ -1,8 +1,6 @@ package tyrian import cats.effect.IO -import io.circe.HCursor -import io.circe.parser.* import tyrian.http.* class ChromeTests extends munit.CatsEffectSuite { diff --git a/tyrian-firefox-tests/src/test/scala/tyrian/FirefoxTests.scala b/tyrian-firefox-tests/src/test/scala/tyrian/FirefoxTests.scala index 4e72ac1c..3698ac11 100644 --- a/tyrian-firefox-tests/src/test/scala/tyrian/FirefoxTests.scala +++ b/tyrian-firefox-tests/src/test/scala/tyrian/FirefoxTests.scala @@ -1,8 +1,6 @@ package tyrian import cats.effect.IO -import io.circe.HCursor -import io.circe.parser.* import tyrian.http.* class FirefoxTests extends munit.CatsEffectSuite { diff --git a/tyrian-indigo-bridge/src/main/scala/tyrian/TyrianIndigoBridge.scala b/tyrian-indigo-bridge/src/main/scala/tyrian/TyrianIndigoBridge.scala index bb8d03c2..a4d6d1ee 100644 --- a/tyrian-indigo-bridge/src/main/scala/tyrian/TyrianIndigoBridge.scala +++ b/tyrian-indigo-bridge/src/main/scala/tyrian/TyrianIndigoBridge.scala @@ -3,8 +3,6 @@ package tyrian import cats.effect.kernel.Async import org.scalajs.dom.Event import org.scalajs.dom.EventTarget -import tyrian.Cmd -import tyrian.Sub import util.Functions import scala.scalajs.js diff --git a/tyrian-io/src/main/scala/tyrian/TyrianApp.scala b/tyrian-io/src/main/scala/tyrian/TyrianApp.scala index 66114b5d..d34930fe 100644 --- a/tyrian-io/src/main/scala/tyrian/TyrianApp.scala +++ b/tyrian-io/src/main/scala/tyrian/TyrianApp.scala @@ -1,11 +1,7 @@ package tyrian import cats.effect.IO -import cats.effect.kernel.Async -import cats.effect.kernel.Resource import cats.effect.unsafe.implicits.global -import tyrian.TyrianAppF -import tyrian.runtime.TyrianRuntime /** The TyrianApp trait can be extended to conveniently prompt you for all the methods needed for a Tyrian app, as well * as providing a number of standard app launching methods. diff --git a/tyrian-zio/src/main/scala/tyrian/TyrianApp.scala b/tyrian-zio/src/main/scala/tyrian/TyrianApp.scala index 9d4b3099..61ee95c1 100644 --- a/tyrian-zio/src/main/scala/tyrian/TyrianApp.scala +++ b/tyrian-zio/src/main/scala/tyrian/TyrianApp.scala @@ -1,15 +1,12 @@ package tyrian -import cats.effect.Async import cats.effect.kernel.Async -import cats.effect.kernel.Resource -import org.scalajs.dom.window -import tyrian.TyrianAppF -import tyrian.runtime.TyrianRuntime import zio.Runtime import zio.Task import zio.Unsafe +import scala.annotation.nowarn + /** The TyrianApp trait can be extended to conveniently prompt you for all the methods needed for a Tyrian app, as well * as providing a number of standard app launching methods. */ @@ -17,6 +14,7 @@ trait TyrianApp[Msg, Model](using Async[Task]) extends TyrianAppF[Task, Msg, Mod private val runtime = Runtime.default + @nowarn("msg=discarded") val run: Task[Nothing] => Unit = runnable => Unsafe.unsafe { implicit unsafe => runtime.unsafe.fork(runnable) diff --git a/tyrian/js/src/main/scala/tyrian/HotReload.scala b/tyrian/js/src/main/scala/tyrian/HotReload.scala index ca419bcf..aa952579 100644 --- a/tyrian/js/src/main/scala/tyrian/HotReload.scala +++ b/tyrian/js/src/main/scala/tyrian/HotReload.scala @@ -2,10 +2,6 @@ package tyrian import cats.effect.kernel.Async import org.scalajs.dom -import util.Functions - -import scala.concurrent.duration.FiniteDuration -import scala.scalajs.js /** A very simple mechanism to allow automatic loading and saving of your applications model to local storage. Uses: * diff --git a/tyrian/js/src/main/scala/tyrian/Location.scala b/tyrian/js/src/main/scala/tyrian/Location.scala index 8c6da701..ca455fb3 100644 --- a/tyrian/js/src/main/scala/tyrian/Location.scala +++ b/tyrian/js/src/main/scala/tyrian/Location.scala @@ -1,15 +1,5 @@ package tyrian -import cats.effect.kernel.Async -import cats.effect.kernel.Resource -import org.scalajs.dom.Element -import org.scalajs.dom.PopStateEvent -import org.scalajs.dom.document -import org.scalajs.dom.window - -import scala.scalajs.js -import scala.scalajs.js.annotation._ - sealed trait Location: def locationDetails: LocationDetails def isInternal: Boolean diff --git a/tyrian/js/src/main/scala/tyrian/Routing.scala b/tyrian/js/src/main/scala/tyrian/Routing.scala index f55f33a4..74a94f5b 100644 --- a/tyrian/js/src/main/scala/tyrian/Routing.scala +++ b/tyrian/js/src/main/scala/tyrian/Routing.scala @@ -1,8 +1,5 @@ package tyrian -import cats.effect.kernel.Async -import org.scalajs.dom.window - /** Provides a number of convenience functions to help with routing in simple use-cases. Here the `Location` type is * typically hidden away and the user is expected to match on the `String` href (if at all). */ diff --git a/tyrian/js/src/main/scala/tyrian/Sub.scala b/tyrian/js/src/main/scala/tyrian/Sub.scala index 2adda388..4a7aa375 100644 --- a/tyrian/js/src/main/scala/tyrian/Sub.scala +++ b/tyrian/js/src/main/scala/tyrian/Sub.scala @@ -2,7 +2,6 @@ package tyrian import cats.Functor import cats.effect.kernel.Async -import cats.effect.kernel.Concurrent import cats.effect.kernel.Fiber import cats.effect.kernel.Sync import cats.kernel.Eq @@ -223,6 +222,7 @@ object Sub: /** A subscription that emits a `msg` based on the running time in seconds whenever the browser renders an animation * frame. */ + @nowarn("msg=discarded") def animationFrameTick[F[_]: Async, Msg](id: String)(toMsg: Double => Msg): Sub[F, Msg] = Sub.make( id, @@ -231,6 +231,7 @@ object Sub: dom.window.requestAnimationFrame { t => cb(Right(toMsg(t / 1000))) } + () } } ) diff --git a/tyrian/js/src/main/scala/tyrian/Tyrian.scala b/tyrian/js/src/main/scala/tyrian/Tyrian.scala index 096f11e8..c22e1d18 100644 --- a/tyrian/js/src/main/scala/tyrian/Tyrian.scala +++ b/tyrian/js/src/main/scala/tyrian/Tyrian.scala @@ -1,16 +1,7 @@ package tyrian import cats.effect.kernel.Async -import cats.effect.kernel.Ref -import cats.effect.kernel.Resource -import cats.effect.std.Dispatcher -import cats.effect.syntax.all._ -import cats.syntax.all._ -import fs2.Stream -import fs2.concurrent.Channel import org.scalajs.dom.Element -import snabbdom.VNode -import tyrian.runtime.ModelHolder import tyrian.runtime.TyrianRuntime import tyrian.runtime.TyrianSSR diff --git a/tyrian/js/src/main/scala/tyrian/TyrianAppF.scala b/tyrian/js/src/main/scala/tyrian/TyrianAppF.scala index 3c45915a..e928f4a6 100644 --- a/tyrian/js/src/main/scala/tyrian/TyrianAppF.scala +++ b/tyrian/js/src/main/scala/tyrian/TyrianAppF.scala @@ -1,14 +1,13 @@ package tyrian import cats.effect.kernel.Async -import cats.effect.kernel.Resource import org.scalajs.dom.DocumentReadyState import org.scalajs.dom.Element import org.scalajs.dom.HTMLElement import org.scalajs.dom.document import org.scalajs.dom.window -import tyrian.runtime.TyrianRuntime +import scala.annotation.nowarn import scala.scalajs.js.Promise import scala.scalajs.js.annotation.* @@ -133,11 +132,13 @@ trait TyrianAppF[F[_]: Async, Msg, Model]: object TyrianAppF: /** Launch app instances after DOMContentLoaded. */ + @nowarn("msg=discarded") def onLoad[F[_]: Async](appDirectory: Map[String, TyrianAppF[F, _, _]]): Unit = val documentReady = new Promise((resolve, _reject) => { document.addEventListener("DOMContentLoaded", _ => resolve(())) if (document.readyState != DocumentReadyState.loading) { resolve(()) + () } }) documentReady.`then`(_ => launch[F](appDirectory)) @@ -148,11 +149,10 @@ object TyrianAppF: /** Find data-tyrian-app HTMLElements and launch corresponding TyrianAppF instances */ def launch[F[_]: Async](appDirectory: Map[String, TyrianAppF[F, _, _]]): Unit = - for { - element <- document.querySelectorAll("[data-tyrian-app]") - } yield { + document.querySelectorAll("[data-tyrian-app]").foreach { element => val tyrianAppElement = element.asInstanceOf[HTMLElement] val tyrianAppName = tyrianAppElement.dataset.get("tyrianApp") + tyrianAppName.flatMap(appDirectory.get) match case Some(appSupplier) => appSupplier.launch(tyrianAppElement, appElementFlags(tyrianAppElement)) diff --git a/tyrian/js/src/main/scala/tyrian/http/Http.scala b/tyrian/js/src/main/scala/tyrian/http/Http.scala index d5323967..f8df524a 100644 --- a/tyrian/js/src/main/scala/tyrian/http/Http.scala +++ b/tyrian/js/src/main/scala/tyrian/http/Http.scala @@ -5,11 +5,10 @@ import cats.implicits.* import org.scalajs.dom import org.scalajs.dom.HttpMethod import org.scalajs.dom.RequestInit -import org.scalajs.dom.XMLHttpRequest import org.scalajs.dom.fetch import tyrian.Cmd -import scala.annotation.targetName +import scala.annotation.nowarn import scala.scalajs.js import scala.util.Try @@ -36,6 +35,7 @@ object Http: */ def send[F[_]: Async, A, Msg](request: Request[A], resultToMessage: Decoder[Msg]): Cmd.Run[F, Msg, Msg] = + @nowarn("msg=discarded") def fetchTask(abortController: dom.AbortController): F[dom.Response] = Async[F].async_ { callback => val requestInit = new RequestInit {} @@ -58,12 +58,18 @@ object Http: fetch(request.url, requestInit) .`then`(response => callback(Right(response))) .`catch`(error => callback(Left(errorToThrowable(error)))) + + () } + + @nowarn("msg=discarded") def textBodyTask(domResponse: dom.Response): F[String] = Async[F].async_ { callback => domResponse .text() .`then`(text => callback(Right(text))) .`catch`(error => callback(Left(errorToThrowable(error)))) + + () } val fullTask = (for { diff --git a/tyrian/js/src/main/scala/tyrian/runtime/Rendering.scala b/tyrian/js/src/main/scala/tyrian/runtime/Rendering.scala index 51a393aa..bd64c56e 100644 --- a/tyrian/js/src/main/scala/tyrian/runtime/Rendering.scala +++ b/tyrian/js/src/main/scala/tyrian/runtime/Rendering.scala @@ -12,7 +12,6 @@ import tyrian.Event import tyrian.Html import tyrian.Location import tyrian.NamedAttribute -import tyrian.Property import tyrian.PropertyBoolean import tyrian.PropertyString import tyrian.RawTag diff --git a/tyrian/js/src/main/scala/tyrian/runtime/TyrianRuntime.scala b/tyrian/js/src/main/scala/tyrian/runtime/TyrianRuntime.scala index 31c3e8dc..93c965c5 100644 --- a/tyrian/js/src/main/scala/tyrian/runtime/TyrianRuntime.scala +++ b/tyrian/js/src/main/scala/tyrian/runtime/TyrianRuntime.scala @@ -1,16 +1,11 @@ package tyrian.runtime -import cats.data.OptionT import cats.effect.kernel.Async -import cats.effect.kernel.Ref -import cats.effect.kernel.Resource import cats.effect.std.AtomicCell import cats.effect.std.Dispatcher import cats.effect.std.Queue import cats.effect.syntax.all.* import cats.syntax.all.* -import fs2.Stream -import fs2.concurrent.Channel import org.scalajs.dom import org.scalajs.dom.Element import snabbdom.VNode @@ -20,6 +15,8 @@ import tyrian.Html import tyrian.Location import tyrian.Sub +import scala.annotation.nowarn + object TyrianRuntime: def apply[F[_], Model, Msg]( @@ -73,8 +70,10 @@ object TyrianRuntime: val renderLoop = val onMsg = (msg: Msg) => dispatcher.unsafeRunAndForget(msgQueue.offer(msg)) + @nowarn("msg=discarded") val requestAnimationFrame = F.async_ { cb => dom.window.requestAnimationFrame(_ => cb(Either.unit)) + () } def redraw(vnode: VNode) = diff --git a/tyrian/js/src/main/scala/tyrian/websocket/WebSocket.scala b/tyrian/js/src/main/scala/tyrian/websocket/WebSocket.scala index f055701d..45222776 100644 --- a/tyrian/js/src/main/scala/tyrian/websocket/WebSocket.scala +++ b/tyrian/js/src/main/scala/tyrian/websocket/WebSocket.scala @@ -1,16 +1,13 @@ package tyrian.websocket import cats.effect.kernel.Async -import cats.effect.kernel.Sync import cats.effect.std.Dispatcher import cats.effect.syntax.all.* import cats.syntax.all.* -import fs2.Stream import fs2.concurrent.Channel import org.scalajs.dom import tyrian.Cmd import tyrian.Sub -import tyrian.websocket.WebSocketEvent import util.Functions import scala.concurrent.duration.* diff --git a/tyrian/js/src/test/scala/tyrian/AttrTests.scala b/tyrian/js/src/test/scala/tyrian/AttrTests.scala index 1faa57a0..e23e980b 100644 --- a/tyrian/js/src/test/scala/tyrian/AttrTests.scala +++ b/tyrian/js/src/test/scala/tyrian/AttrTests.scala @@ -1,8 +1,6 @@ package tyrian -import org.scalajs.dom.document import tyrian.Html.* -import tyrian.runtime.TyrianRuntime class AttrTests extends munit.FunSuite { diff --git a/tyrian/js/src/test/scala/tyrian/CmdLawsTest.scala b/tyrian/js/src/test/scala/tyrian/CmdLawsTest.scala index 4024f60b..626b6072 100644 --- a/tyrian/js/src/test/scala/tyrian/CmdLawsTest.scala +++ b/tyrian/js/src/test/scala/tyrian/CmdLawsTest.scala @@ -4,11 +4,8 @@ import cats.Id import cats.kernel.laws.discipline.EqTests import cats.kernel.laws.discipline.MonoidTests import cats.laws.discipline.FunctorTests -import cats.syntax.foldable.* import org.scalacheck.Arbitrary import org.scalacheck.Cogen -import org.scalacheck.Gen -import org.scalacheck.rng.Seed import tyrian.runtime.CmdHelper class CmdLawsTests extends munit.DisciplineSuite { diff --git a/tyrian/js/src/test/scala/tyrian/CmdSubUtils.scala b/tyrian/js/src/test/scala/tyrian/CmdSubUtils.scala index bb841aa5..76556285 100644 --- a/tyrian/js/src/test/scala/tyrian/CmdSubUtils.scala +++ b/tyrian/js/src/test/scala/tyrian/CmdSubUtils.scala @@ -2,6 +2,8 @@ package tyrian import cats.effect.IO +import scala.annotation.nowarn + object CmdSubUtils: extension [A](cmd: Cmd[IO, A]) def run: IO[A] = runCmd(cmd) @@ -21,11 +23,13 @@ object CmdSubUtils: extension [A](sub: Sub[IO, A]) def run: (Either[Throwable, A] => Unit) => IO[Unit] = runSub(sub) @SuppressWarnings(Array("scalafix:DisableSyntax.throw")) + @nowarn("msg=discarded") def runSub[A, Msg](sub: Sub[IO, Msg])(callback: Either[Throwable, A] => Unit): IO[Unit] = sub match case s: Sub.Observe[IO, A, Msg] @unchecked => s.observable.map { run => run(callback) + () } case _ => diff --git a/tyrian/js/src/test/scala/tyrian/HtmlTests.scala b/tyrian/js/src/test/scala/tyrian/HtmlTests.scala index 159837d3..62330cf8 100644 --- a/tyrian/js/src/test/scala/tyrian/HtmlTests.scala +++ b/tyrian/js/src/test/scala/tyrian/HtmlTests.scala @@ -2,8 +2,6 @@ package tyrian import tyrian.Html.* -import scala.annotation.targetName - class HtmlTests extends munit.FunSuite { test("'draggable' attribute can have different types") { diff --git a/tyrian/js/src/test/scala/tyrian/SubLawsTest.scala b/tyrian/js/src/test/scala/tyrian/SubLawsTest.scala index c8b9f51e..52fa67a7 100644 --- a/tyrian/js/src/test/scala/tyrian/SubLawsTest.scala +++ b/tyrian/js/src/test/scala/tyrian/SubLawsTest.scala @@ -4,11 +4,8 @@ import cats.effect.IO import cats.kernel.laws.discipline.EqTests import cats.kernel.laws.discipline.MonoidTests import cats.laws.discipline.FunctorTests -import cats.syntax.foldable.* import org.scalacheck.Arbitrary import org.scalacheck.Cogen -import org.scalacheck.Gen -import org.scalacheck.rng.Seed import tyrian.runtime.SubHelper class SubLawsTests extends munit.DisciplineSuite {