Skip to content

Commit 426ecd1

Browse files
committed
Update cats 0.x->2.x, CE 0.x->3.x, scala -> 2.13
1 parent 5912ac6 commit 426ecd1

File tree

22 files changed

+282
-267
lines changed

22 files changed

+282
-267
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
.idea/
22
target/
3+
.bloop/
4+
.metals/
5+
metals.sbt
6+
.vscode/settings.json

.scalafmt.conf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
version = "3.0.5"
12
align.openParenCallSite = false
2-
danglingParentheses = true
3+
danglingParentheses.preset = true
34
maxColumn = 100
4-
project.git = true
5+
# project.git = true
56
rewrite.rules = [RedundantBraces, RedundantParens, SortImports, PreferCurlyFors]
6-
docstrings = JavaDoc
7+
# docstrings = JavaDoc

build.sbt

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,7 @@ name := "taklib"
22

33
lazy val commonSettings = Seq(
44
version := "0.2.0",
5-
scalaVersion := "2.12.1",
6-
scalacOptions ++= Seq(
7-
"-deprecation",
8-
"-encoding", "UTF-8", // yes, this is 2 args
9-
"-feature",
10-
"-unchecked",
11-
"-Xfatal-warnings",
12-
"-Xlint",
13-
"-Yno-adapted-args",
14-
// "-Ywarn-dead-code", // N.B. doesn't work well with the ??? hole
15-
"-Ywarn-numeric-widen",
16-
"-Ywarn-value-discard",
17-
"-Ywarn-unused",
18-
"-Ywarn-unused-import",
19-
"-Xfuture",
20-
"-Ypartial-unification"
21-
)
5+
scalaVersion := "2.13.8"
226
)
237

248
lazy val taklib = (project in file("taklib"))
@@ -34,54 +18,63 @@ lazy val opentak = (project in file("opentak"))
3418
.settings(commonSettings, name := "opentak")
3519

3620
// Remove these options in 'sbt console' because they're not nice for interactive usage
37-
scalacOptions in (taklib, Compile, console) ~= (_.filterNot(Set("-Xfatal-warnings", "-Ywarn-unused-import").contains))
38-
scalacOptions in (takcli, Compile, console) ~= (_.filterNot(Set("-Xfatal-warnings", "-Ywarn-unused-import").contains))
39-
scalacOptions in (tpsserver, Compile, console) ~= (_.filterNot(Set("-Xfatal-warnings", "-Ywarn-unused-import").contains))
40-
scalacOptions in (opentak, Compile, console) ~= (_.filterNot(Set("-Xfatal-warnings", "-Ywarn-unused-import").contains))
21+
scalacOptions in (taklib, Compile, console) ~= (_.filterNot(
22+
Set("-Xfatal-warnings", "-Ywarn-unused-import").contains
23+
))
24+
scalacOptions in (takcli, Compile, console) ~= (_.filterNot(
25+
Set("-Xfatal-warnings", "-Ywarn-unused-import").contains
26+
))
27+
scalacOptions in (tpsserver, Compile, console) ~= (_.filterNot(
28+
Set("-Xfatal-warnings", "-Ywarn-unused-import").contains
29+
))
30+
scalacOptions in (opentak, Compile, console) ~= (_.filterNot(
31+
Set("-Xfatal-warnings", "-Ywarn-unused-import").contains
32+
))
4133

4234
resolvers += Resolver.sonatypeRepo("releases")
4335

44-
val catsVersion = "0.9.0"
45-
val parserCombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.5"
36+
val catsVersion = "2.7.0"
37+
val parserCombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % "2.1.0"
4638
val dependencies = Seq(
47-
"org.typelevel" %% "cats" % catsVersion,
39+
"org.typelevel" %% "cats-core" % catsVersion,
4840
parserCombinators,
49-
"org.scala-graph" %% "graph-core" % "1.11.4"
41+
"org.scala-graph" %% "graph-core" % "1.13.4"
5042
)
5143
val testDependencies = Seq(
52-
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
53-
"org.scalacheck" %% "scalacheck" % "1.13.4" % "test",
54-
"com.ironcorelabs" %% "cats-scalatest" % "2.2.0" % "test"
44+
"org.scalatest" %% "scalatest" % "3.2.11" % "test",
45+
"org.scalacheck" %% "scalacheck" % "1.15.4" % "test",
46+
"com.ironcorelabs" %% "cats-scalatest" % "3.1.1" % "test",
47+
"org.typelevel" %% "discipline-core" % "1.4.0" % "test",
48+
"org.typelevel" %% "discipline-scalatest" % "2.0.0",
49+
"org.typelevel" %% "cats-kernel-laws" % catsVersion % "test",
50+
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.11.0" % "test"
5551
)
5652

57-
libraryDependencies in taklib ++= dependencies
58-
libraryDependencies in taklib ++= testDependencies
59-
libraryDependencies in takcli ++= Seq(
60-
"org.typelevel" %% "cats-effect" % "0.2"
53+
taklib / libraryDependencies ++= dependencies
54+
taklib / libraryDependencies ++= testDependencies
55+
takcli / libraryDependencies ++= Seq(
56+
"org.typelevel" %% "cats-effect" % "3.3.5"
6157
)
6258

6359
resolvers in tpsserver += Resolver.sonatypeRepo("snapshots")
64-
val http4sVersion = "0.17.0-M1"
65-
val circeVersion = "0.7.0"
66-
libraryDependencies in tpsserver ++= Seq(
67-
"io.circe" %% "circe-core" % circeVersion,
60+
val http4sVersion = "0.23.10"
61+
val circeVersion = "0.14.1"
62+
tpsserver / libraryDependencies ++= Seq(
63+
"io.circe" %% "circe-core" % circeVersion,
6864
"io.circe" %% "circe-generic" % circeVersion,
69-
"io.circe" %% "circe-parser" % circeVersion,
65+
"io.circe" %% "circe-parser" % circeVersion,
7066
"io.circe" %% "circe-optics" % circeVersion % "test",
71-
7267
"org.http4s" %% "http4s-blaze-server" % http4sVersion,
73-
"org.http4s" %% "http4s-circe" % http4sVersion,
74-
"org.http4s" %% "http4s-dsl" % http4sVersion,
68+
"org.http4s" %% "http4s-circe" % http4sVersion,
69+
"org.http4s" %% "http4s-dsl" % http4sVersion,
7570
"org.http4s" %% "http4s-blaze-client" % http4sVersion % "test",
76-
"org.http4s" %% "http4s-client" % http4sVersion % "test",
77-
71+
"org.http4s" %% "http4s-client" % http4sVersion % "test",
7872
"ch.qos.logback" % "logback-classic" % "1.2.1"
7973
) ++ testDependencies
8074

81-
libraryDependencies in opentak += parserCombinators
82-
libraryDependencies in opentak ++= testDependencies
83-
75+
opentak / libraryDependencies += parserCombinators
76+
opentak / libraryDependencies ++= testDependencies
8477

8578
initialCommands in (taklib, console) += "import com.github.daenyth.taklib._"
8679

87-
coverageEnabled in taklib := true
80+
// coverageEnabled in taklib := true

opentak/src/main/scala/com/github/daenyth/opentak/protocol/PlaytakCodec.scala

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import com.github.daenyth.taklib.Implicits.RichParsing
55
import com.github.daenyth.taklib._
66

77
import scala.util.parsing.combinator.RegexParsers
8+
import scala.annotation.nowarn
89

9-
/**
10-
* Playtak protocol encoding/decoding between the wire
11-
* representation (string) and in-library representation (case classes)
12-
*
13-
* See PlaytakCodec#encode and PlaytakCodec#decode
14-
*/
10+
/** Playtak protocol encoding/decoding between the wire representation (string) and in-library
11+
* representation (case classes)
12+
*
13+
* See PlaytakCodec#encode and PlaytakCodec#decode
14+
*/
1515
object PlaytakCodec {
1616
def encode(outgoing: Playtak.Outgoing): String =
1717
Outgoing.encode(outgoing)
@@ -26,9 +26,8 @@ object PlaytakCodec {
2626

2727
import Playtak.Incoming._
2828

29-
val client: Parser[Client] = "Client" ~ "([A-Za-z-.0-9]{4,15})".r ^^ {
30-
case _ ~ s =>
31-
Client(s)
29+
val client: Parser[Client] = "Client" ~ "([A-Za-z-.0-9]{4,15})".r ^^ { case _ ~ s =>
30+
Client(s)
3231
}
3332

3433
val msg: Parser[String] = """[^\n\r]{1,256}""".r
@@ -48,9 +47,8 @@ object PlaytakCodec {
4847
def simpleGameMessage[A](str: String, gameMsg: GameNumber => A): Parser[A] =
4948
gameNumber <~ str ^^ gameMsg
5049

51-
val register: Parser[Register] = "Register" ~> username ~ email ^^ {
52-
case username ~ email =>
53-
Register(username, email)
50+
val register: Parser[Register] = "Register" ~> username ~ email ^^ { case username ~ email =>
51+
Register(username, email)
5452
}
5553
val userLogin: Parser[UserLogin] = "Login" ~> username ~ password ^^ {
5654
case username ~ password =>
@@ -63,7 +61,7 @@ object PlaytakCodec {
6361
val asPlayer = color match {
6462
case "W" => Some(White)
6563
case "B" => Some(Black)
66-
case _ => None
64+
case _ => None
6765
}
6866
Seek(size, time, increment, asPlayer)
6967
}
@@ -75,7 +73,7 @@ object PlaytakCodec {
7573
val playStone = stoneType match {
7674
case "C" => PlayCapstone(idx)
7775
case "W" => PlayStanding(idx)
78-
case _ => PlayFlat(idx)
76+
case _ => PlayFlat(idx)
7977
}
8078
Place(gameNumber, playStone)
8179
}
@@ -101,8 +99,8 @@ object PlaytakCodec {
10199
val shout: Parser[Shout] = "Shout" ~> msg ^^ Shout
102100
val joinRoom: Parser[JoinRoom] = "JoinRoom" ~> roomName ^^ JoinRoom
103101
val leaveRoom: Parser[LeaveRoom] = "LeaveRoom" ~> roomName ^^ LeaveRoom
104-
val shoutRoom: Parser[ShoutRoom] = "ShoutRoom" ~> roomName ~ msg ^^ {
105-
case room ~ msg => ShoutRoom(room, msg)
102+
val shoutRoom: Parser[ShoutRoom] = "ShoutRoom" ~> roomName ~ msg ^^ { case room ~ msg =>
103+
ShoutRoom(room, msg)
106104
}
107105
val tell: Parser[Tell] = "Tell" ~> username ~ msg ^^ { case user ~ msg => Tell(user, msg) }
108106
val ping: Parser[Ping.type] = "^PING$".r ^^^ Ping
@@ -119,21 +117,21 @@ object PlaytakCodec {
119117
def encode(outgoing: Playtak.Outgoing): String = {
120118
import Playtak.Outgoing._
121119
outgoing match {
122-
case Welcome => "Welcome!"
123-
case LoginOrRegisterNow => "Login or Register"
124-
case WelcomeUser(username) => s"Welcome $username"
125-
case ge: GameEvent => encodeGameEvent(ge)
126-
case Shout(username, msg) => s"Shout <$username> $msg"
127-
case RoomJoined(name) => s"Joined room $name"
128-
case RoomLeft(name) => s"Left room $name"
120+
case Welcome => "Welcome!"
121+
case LoginOrRegisterNow => "Login or Register"
122+
case WelcomeUser(username) => s"Welcome $username"
123+
case ge: GameEvent => encodeGameEvent(ge)
124+
case Shout(username, msg) => s"Shout <$username> $msg"
125+
case RoomJoined(name) => s"Joined room $name"
126+
case RoomLeft(name) => s"Left room $name"
129127
case ShoutRoom(name, username, msg) => s"ShoutRoom $name <$username> $msg"
130-
case Tell(username, msg) => s"Tell <$username> $msg"
131-
case Told(username, msg) => s"Told <$username> $msg"
132-
case ServerMessage(msg) => s"Message $msg"
133-
case Error(msg) => s"Error $msg"
134-
case OnlineUsers(count) => s"Online $count"
135-
case NOK => "NOK"
136-
case OK => "OK"
128+
case Tell(username, msg) => s"Tell <$username> $msg"
129+
case Told(username, msg) => s"Told <$username> $msg"
130+
case ServerMessage(msg) => s"Message $msg"
131+
case Error(msg) => s"Error $msg"
132+
case OnlineUsers(count) => s"Online $count"
133+
case NOK => "NOK"
134+
case OK => "OK"
137135
}
138136
}
139137

@@ -155,10 +153,12 @@ object PlaytakCodec {
155153
s"Game Start $gameNumber $size $whitePlayerusername vs $blackPlayerusername $yourColor"
156154
case Place(gameNumber, playStone) =>
157155
import Stone._
156+
// TODO this is just totally broken
157+
@nowarn
158158
val stoneType = playStone.stone match {
159-
case _: Capstone => "C"
159+
case _: Capstone => "C"
160160
case _: StandingStone => "W"
161-
case _: FlatStone => ""
161+
case _: FlatStone => ""
162162
}
163163
s"Game#$gameNumber P ${playStone.at.name} $stoneType"
164164
case m: Move =>
@@ -175,7 +175,7 @@ object PlaytakCodec {
175175
case DoubleRoad =>
176176
"R-R" // Not actually supported by playtak or default rules, but different result sets can treat it differently.
177177
case FlatWin(player) => player.fold("0-F", "F-0")
178-
case Draw => "1/2-1/2"
178+
case Draw => "1/2-1/2"
179179
case WinByResignation(player) =>
180180
player.fold("0-1", "1-0") // Again not supported by playtak; this is PTN format
181181
}

opentak/src/test/scala/com/github/daenyth/opentak/protocol/PlaytakCodecTest.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package com.github.daenyth.opentak.protocol
22

33
import com.github.daenyth.opentak.protocol.Playtak.{GameNumber, Username}
44
import com.github.daenyth.taklib.White
5-
import org.scalatest.{EitherValues, FlatSpec, Matchers}
5+
import org.scalatest.EitherValues
6+
import org.scalatest.flatspec.AnyFlatSpec
7+
import org.scalatest.matchers.should.Matchers
68

7-
class PlaytakCodecTest extends FlatSpec with Matchers with EitherValues {
9+
class PlaytakCodecTest extends AnyFlatSpec with Matchers with EitherValues {
810
import PlaytakCodec.Incoming._
911
import Playtak.Incoming._
1012

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 0.13.13
1+
sbt.version = 1.6.1

project/plugins.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
logLevel := Level.Warn
1+
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20")
22

3-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0")
3+
// addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0")
44

5-
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.1.0")
5+
// addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.1.0")

takcli/src/main/scala/com/github/daenyth/takcli/Main.scala

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ import com.github.daenyth.taklib._
55

66
import scala.io.StdIn
77
import scala.util.control.NoStackTrace
8-
import cats.syntax.flatMap._
9-
import cats.syntax.applicativeError._
8+
import cats.syntax.all._
9+
import cats.effect.IOApp
10+
import cats.effect.ExitCode
1011

11-
object Main {
12+
object Main extends IOApp {
1213

13-
def main(args: Array[String]): Unit =
14+
def run(args: List[String]): IO[ExitCode] =
1415
mainT
15-
.recoverWith {
16-
case CleanExit => IO(println("Exiting"))
16+
.recoverWith { case CleanExit =>
17+
IO.println("Exiting")
1718
}
18-
.unsafeRunSync()
19+
.as(ExitCode.Success)
1920

2021
def mainT: IO[Unit] = printStartup >> getInitialGame >>= runGameLoop
2122

2223
def getInitialGame: IO[Game] = promptSize.flatMap {
2324
Game.ofSize(_) match {
24-
case scala.Left(err) => IO(println(err)) >> getInitialGame
25+
case scala.Left(err) => IO(println(err)) >> getInitialGame
2526
case scala.Right(game) => IO(game)
2627
}
2728
}
@@ -45,10 +46,10 @@ object Main {
4546

4647
def printGame(g: Game) = IO {
4748
val nextPlayInfo = g.turnNumber match {
48-
case 1 => "White to play (Black stone)"
49-
case 2 => "Black to play (White stone)"
49+
case 1 => "White to play (Black stone)"
50+
case 2 => "Black to play (White stone)"
5051
case n if n % 2 == 0 => "Black to play"
51-
case _ => "White to play"
52+
case _ => "White to play"
5253
}
5354
println(s"Move ${g.turnNumber} - $nextPlayInfo")
5455
print(pretty(g))
@@ -61,8 +62,8 @@ object Main {
6162
IO {
6263
print("Game size?\n > ")
6364
StdIn.readInt()
64-
}.recoverWith {
65-
case n: NumberFormatException => IO(println(s"Bad size: $n")) >> promptSize
65+
}.recoverWith { case n: NumberFormatException =>
66+
IO(println(s"Bad size: $n")) >> promptSize
6667
}
6768

6869
def pretty(g: Game): String =
@@ -75,16 +76,17 @@ object Main {
7576
def promptAction: IO[TurnAction] =
7677
IO(StdIn.readLine("Your Move?\n > "))
7778
.flatMap { input =>
78-
if (input == null) { throw CleanExit } else
79+
if (input == null) { throw CleanExit }
80+
else
7981
PtnParser
8082
.parseEither(PtnParser.turnAction, input)
8183
.fold(
8284
err => IO.raiseError(PtnParseError(err)),
8385
ta => IO.pure(ta)
8486
)
8587
}
86-
.recoverWith {
87-
case PtnParseError(err) => IO(println(s"Bad move: $err")) >> promptAction
88+
.recoverWith { case PtnParseError(err) =>
89+
IO(println(s"Bad move: $err")) >> promptAction
8890
}
8991
}
9092

taklib/src/main/scala/com/github/daenyth/taklib/Board.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import com.github.daenyth.taklib.Stone._
66

77
import scala.annotation.tailrec
88
import scala.collection.immutable.IndexedSeq
9-
import cats.syntax.either._
10-
import cats.syntax.monoid._
11-
import cats.instances.vector._
9+
import cats.syntax.all._
1210
import cats.{Eq => Equal}
1311

1412
import scala.util.Try

0 commit comments

Comments
 (0)