Skip to content

Commit

Permalink
Scalafmt convertToNewSyntax
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Sep 5, 2024
1 parent 4b749f1 commit 791450a
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ style = defaultWithAlign
maxColumn = 120
rewrite.rules = [RedundantBraces,RedundantParens,PreferCurlyFors]
danglingParentheses.preset = true

rewrite.scala3.convertToNewSyntax = true
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tyrian-browser-tests/src/test/scala/tyrian/HttpTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
10 changes: 5 additions & 5 deletions tyrian-tags/shared/src/main/scala/tyrian/HTMLRendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ 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}</${tag.name}>"""
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</${tag.name}>"""

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
Expand Down
2 changes: 1 addition & 1 deletion tyrian/src/main/scala/tyrian/TyrianApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
()
}
Expand Down
4 changes: 2 additions & 2 deletions tyrian/src/main/scala/tyrian/cmds/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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))
}

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))
}
Expand Down
6 changes: 3 additions & 3 deletions tyrian/src/main/scala/tyrian/runtime/CmdHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tyrian/src/main/scala/tyrian/runtime/SubHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tyrian/src/test/scala/tyrian/CmdSubUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion tyrian/src/test/scala/tyrian/SubTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 791450a

Please sign in to comment.