From 791450a966283a2bb47678ded9b684cac5440b40 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Sep 2024 10:23:56 +0100 Subject: [PATCH] Scalafmt convertToNewSyntax --- .scalafmt.conf | 2 ++ .../.jvm/src/main/scala/example/InfiniteScroll.scala | 2 +- .../.jvm/src/main/scala/example/WebSocketsPage.scala | 2 +- .../src/test/scala/tyrian/HttpTests.scala | 2 +- .../src/test/scala/tyrian/ChromeTests.scala | 2 +- .../src/test/scala/tyrian/FirefoxTests.scala | 2 +- .../shared/src/main/scala/tyrian/HTMLRendering.scala | 10 +++++----- tyrian/src/main/scala/tyrian/TyrianApp.scala | 2 +- tyrian/src/main/scala/tyrian/cmds/Logger.scala | 4 ++-- tyrian/src/main/scala/tyrian/runtime/CmdHelper.scala | 6 +++--- tyrian/src/main/scala/tyrian/runtime/SubHelper.scala | 2 +- tyrian/src/test/scala/tyrian/CmdSubUtils.scala | 2 +- tyrian/src/test/scala/tyrian/SubTests.scala | 2 +- 13 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index eb4eb995..83f3a94a 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -4,3 +4,5 @@ style = defaultWithAlign maxColumn = 120 rewrite.rules = [RedundantBraces,RedundantParens,PreferCurlyFors] danglingParentheses.preset = true + +rewrite.scala3.convertToNewSyntax = true diff --git a/sandbox-ssr/.jvm/src/main/scala/example/InfiniteScroll.scala b/sandbox-ssr/.jvm/src/main/scala/example/InfiniteScroll.scala index 21008ac8..4cc45498 100644 --- a/sandbox-ssr/.jvm/src/main/scala/example/InfiniteScroll.scala +++ b/sandbox-ssr/.jvm/src/main/scala/example/InfiniteScroll.scala @@ -25,7 +25,7 @@ object InfiniteScroll: } private def row(index: Long, lastRow: Boolean, nextPage: Long): Html[Nothing] = - val attrs = if (lastRow) { + val attrs = if lastRow then { List(hxGet := s"/scroll?page=$nextPage", hxTrigger := "revealed", hxSwap := "afterend", hxTarget := "this") } else { List() diff --git a/sandbox-ssr/.jvm/src/main/scala/example/WebSocketsPage.scala b/sandbox-ssr/.jvm/src/main/scala/example/WebSocketsPage.scala index 6383bdb4..aa684f2a 100644 --- a/sandbox-ssr/.jvm/src/main/scala/example/WebSocketsPage.scala +++ b/sandbox-ssr/.jvm/src/main/scala/example/WebSocketsPage.scala @@ -19,7 +19,7 @@ object WebSocketsPage: row <- 0 until game.height column <- 0 until game.width isLive = game.cells.contains(Point(column, row)) - color = if (isLive) "#000000" else "#AAAAAA" + color = if isLive then "#000000" else "#AAAAAA" } yield rect( width := cellSize - 1, height := cellSize - 1, diff --git a/tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala b/tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala index fab6aaab..694e81f3 100644 --- a/tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala +++ b/tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala @@ -22,7 +22,7 @@ class HttpTests extends munit.CatsEffectSuite { private def runCmd[Msg](cmd: Cmd[IO, Msg]): IO[Msg] = cmd match - case c: Cmd.Run[IO, _, _] => + case c: Cmd.Run[IO, ?, ?] => c.task.map(c.toMsg) case Cmd.Emit(msg) => diff --git a/tyrian-chrome-tests/src/test/scala/tyrian/ChromeTests.scala b/tyrian-chrome-tests/src/test/scala/tyrian/ChromeTests.scala index 4df9e1e4..e84c3dc5 100644 --- a/tyrian-chrome-tests/src/test/scala/tyrian/ChromeTests.scala +++ b/tyrian-chrome-tests/src/test/scala/tyrian/ChromeTests.scala @@ -10,7 +10,7 @@ class ChromeTests extends munit.CatsEffectSuite { private def runCmd[Msg](cmd: Cmd[IO, Msg]): IO[Msg] = cmd match - case c: Cmd.Run[IO, _, _] => + case c: Cmd.Run[IO, ?, ?] => c.task.map(c.toMsg) case Cmd.Emit(msg) => diff --git a/tyrian-firefox-tests/src/test/scala/tyrian/FirefoxTests.scala b/tyrian-firefox-tests/src/test/scala/tyrian/FirefoxTests.scala index 3698ac11..8e70c6dc 100644 --- a/tyrian-firefox-tests/src/test/scala/tyrian/FirefoxTests.scala +++ b/tyrian-firefox-tests/src/test/scala/tyrian/FirefoxTests.scala @@ -10,7 +10,7 @@ class FirefoxTests extends munit.CatsEffectSuite { private def runCmd[Msg](cmd: Cmd[IO, Msg]): IO[Msg] = cmd match - case c: Cmd.Run[IO, _, _] => + case c: Cmd.Run[IO, ?, ?] => c.task.map(c.toMsg) case Cmd.Emit(msg) => diff --git a/tyrian-tags/shared/src/main/scala/tyrian/HTMLRendering.scala b/tyrian-tags/shared/src/main/scala/tyrian/HTMLRendering.scala index 2d0697cf..693e5abd 100644 --- a/tyrian-tags/shared/src/main/scala/tyrian/HTMLRendering.scala +++ b/tyrian-tags/shared/src/main/scala/tyrian/HTMLRendering.scala @@ -11,23 +11,23 @@ extension [Msg](elem: Elem[Msg]) elem match case _: Empty.type => "" case t: Text => t.value - case h: Html[_] => h.render + case h: Html[?] => h.render extension [Msg](html: Html[Msg]) def render: String = html match - case tag: RawTag[_] => + case tag: RawTag[?] => val attributes = spacer(tag.attributes.map(_.render).filterNot(_.isEmpty).mkString(" ")) s"""<${tag.name}$attributes>${tag.innerHTML}""" - case tag: Tag[_] => + case tag: Tag[?] => val attributes = spacer(tag.attributes.map(_.render).filterNot(_.isEmpty).mkString(" ")) val children = tag.children.map { case _: Empty.type => "" case t: Text => t.value - case h: Html[_] => h.render + case h: Html[?] => h.render }.mkString s"""<${tag.name}$attributes>$children""" @@ -35,7 +35,7 @@ extension [Msg](html: Html[Msg]) extension (a: Attr[?]) def render: String = a match - case _: Event[_, _] => "" + case _: Event[?, ?] => "" case a: Attribute => a.render case p: Property => p.render case a: NamedAttribute => a.name diff --git a/tyrian/src/main/scala/tyrian/TyrianApp.scala b/tyrian/src/main/scala/tyrian/TyrianApp.scala index 3e666c6a..788b852a 100644 --- a/tyrian/src/main/scala/tyrian/TyrianApp.scala +++ b/tyrian/src/main/scala/tyrian/TyrianApp.scala @@ -137,7 +137,7 @@ object TyrianApp: def onLoad[F[_]: Async](appDirectory: Map[String, TyrianApp[F, ?, ?]]): Unit = val documentReady = new Promise((resolve, _reject) => { document.addEventListener("DOMContentLoaded", _ => resolve(())) - if (document.readyState != DocumentReadyState.loading) { + if document.readyState != DocumentReadyState.loading then { resolve(()) () } diff --git a/tyrian/src/main/scala/tyrian/cmds/Logger.scala b/tyrian/src/main/scala/tyrian/cmds/Logger.scala index a050831f..c2bdeb44 100644 --- a/tyrian/src/main/scala/tyrian/cmds/Logger.scala +++ b/tyrian/src/main/scala/tyrian/cmds/Logger.scala @@ -26,7 +26,7 @@ object Logger: private val errorString: String => Unit = message => println(formatMessage(ERROR, message)) private val errorOnceString: String => Unit = message => - if (!errorLogs.contains(message)) { + if !errorLogs.contains(message) then { errorLogs += message println(formatMessage(ERROR, message)) } @@ -34,7 +34,7 @@ object Logger: private val debugString: String => Unit = message => println(formatMessage(DEBUG, message)) private val debugOnceString: String => Unit = message => - if (!debugLogs.contains(message)) { + if !debugLogs.contains(message) then { debugLogs += message println(formatMessage(DEBUG, message)) } diff --git a/tyrian/src/main/scala/tyrian/runtime/CmdHelper.scala b/tyrian/src/main/scala/tyrian/runtime/CmdHelper.scala index 62add567..1c93f411 100644 --- a/tyrian/src/main/scala/tyrian/runtime/CmdHelper.scala +++ b/tyrian/src/main/scala/tyrian/runtime/CmdHelper.scala @@ -22,15 +22,15 @@ object CmdHelper: case Cmd.None => rec(cmds) - case c: Cmd.Emit[_] => + case c: Cmd.Emit[?] => acc += Applicative[F].map(c.toTask)(Option.apply) rec(cmds) - case c: Cmd.SideEffect[_, _] => + case c: Cmd.SideEffect[?, ?] => acc += Applicative[F].map(c.toTask)(_ => Option.empty[Msg]) rec(cmds) - case c: Cmd.Run[_, _, _] => + case c: Cmd.Run[?, ?, ?] => acc += Applicative[F].map(c.toTask)(Option.apply) rec(cmds) diff --git a/tyrian/src/main/scala/tyrian/runtime/SubHelper.scala b/tyrian/src/main/scala/tyrian/runtime/SubHelper.scala index 6f0b8f31..720c9447 100644 --- a/tyrian/src/main/scala/tyrian/runtime/SubHelper.scala +++ b/tyrian/src/main/scala/tyrian/runtime/SubHelper.scala @@ -27,7 +27,7 @@ object SubHelper: case Sub.Batch(sbs) :: ss => rec(sbs ++ ss, acc) - case (s: Sub.Observe[_, _, _]) :: ss => + case (s: Sub.Observe[?, ?, ?]) :: ss => rec(ss, s.asInstanceOf[Sub.Observe[F, ?, Msg]] :: acc) rec(List(sub), Nil) diff --git a/tyrian/src/test/scala/tyrian/CmdSubUtils.scala b/tyrian/src/test/scala/tyrian/CmdSubUtils.scala index 3a6ea0ce..448f0010 100644 --- a/tyrian/src/test/scala/tyrian/CmdSubUtils.scala +++ b/tyrian/src/test/scala/tyrian/CmdSubUtils.scala @@ -11,7 +11,7 @@ object CmdSubUtils: @SuppressWarnings(Array("scalafix:DisableSyntax.throw")) def runCmd[Msg](cmd: Cmd[IO, Msg]): IO[Msg] = cmd match - case c: Cmd.Run[IO, _, _] => + case c: Cmd.Run[IO, ?, ?] => c.task.map(c.toMsg) case Cmd.Emit(msg) => diff --git a/tyrian/src/test/scala/tyrian/SubTests.scala b/tyrian/src/test/scala/tyrian/SubTests.scala index 52fb0d6e..953bb510 100644 --- a/tyrian/src/test/scala/tyrian/SubTests.scala +++ b/tyrian/src/test/scala/tyrian/SubTests.scala @@ -124,7 +124,7 @@ class SubTests extends munit.CatsEffectSuite { ) batched.subs match - case s1 :: (ss: Sub.Combine[IO, _]) :: Nil => + case s1 :: (ss: Sub.Combine[IO, ?]) :: Nil => IO.both( s1.run(callback).map(_ => state == 10).assert, IO.both(