Skip to content

Commit b0160bd

Browse files
authored
Merge pull request #19 from somdoron/main
scalafmt configuration
2 parents 5cd66c7 + 2f28b67 commit b0160bd

25 files changed

+84
-70
lines changed

.scalafmt-cross.conf

Lines changed: 0 additions & 14 deletions
This file was deleted.

.scalafmt.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,25 @@ maxColumn = 120
44
indent.defnSite = 2
55
indent.caseSite = 2
66
newlines.source=keep
7+
8+
rewrite.scala3.convertToNewSyntax = true
9+
rewrite.scala3.removeOptionalBraces = {
10+
enabled = true
11+
}
12+
rewrite.scala3.insertEndMarkerMinLines = 50
13+
rewrite.scala3.removeEndMarkerMaxLines = 49
14+
15+
fileOverride {
16+
"glob:**/zio1-zmq/src/main/scala/**" {
17+
runner.dialect = scala213source3
18+
}
19+
"glob:**/zio1-zmq/src/main/scala-2.13/**" {
20+
runner.dialect = scala213source3
21+
}
22+
"glob:**/zio2-zmq/src/main/scala/**" {
23+
runner.dialect = scala213source3
24+
}
25+
"glob:**/zio2-zmq/src/main/scala-2.13/**" {
26+
runner.dialect = scala213source3
27+
}
28+
}

build.sbt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ lazy val zio1zmq = project
140140
.settings(
141141
name := "zio1-zmq",
142142
crossScalaVersions := supportedScalaVersions,
143-
scalafmtConfig := file(".scalafmt-cross.conf"),
144143
scalacOptions ++= commonScalacOptions.value,
145144
libraryDependencies ++= Seq(
146145
"dev.zio" %% "zio" % zio1Version,
@@ -162,7 +161,6 @@ lazy val zio2zmq = project
162161
name := "zio2-zmq",
163162
scalaVersion := mainScalaVersion,
164163
crossScalaVersions := supportedScalaVersions,
165-
scalafmtConfig := file(".scalafmt-cross.conf"),
166164
scalacOptions ++= commonScalacOptions.value,
167165
libraryDependencies ++= Seq(
168166
"dev.zio" %% "zio" % zio2Version,

raft-zmq/src/main/scala/zio/raft/zmq/ProtocolMessage.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@ object ProtocolMessage:
1919
.typecase(2, RpcMessageCodec.codec[A].as[ProtocolMessage.Rpc[A]])
2020

2121
private def memberIdCodec = utf8_32.xmap(MemberId(_), _.value)
22-
23-
end ProtocolMessage

raft-zmq/src/main/scala/zio/raft/zmq/RpcMessageCodec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,4 @@ object RpcMessageCodec:
107107
.by(uint8)
108108
.typecase(0, (memberIdCodec :: termCodec :: indexCodec :: bool(8)).as[InstallSnapshotResult.Success[A]])
109109
.typecase(1, (memberIdCodec :: termCodec :: indexCodec).as[InstallSnapshotResult.Failure[A]])
110+
end RpcMessageCodec

raft-zmq/src/main/scala/zio/raft/zmq/ZmqRpc.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class ZmqRpc[A <: Command: Codec](server: ZSocket, clients: Map[MemberId, ZSocke
9494
.collectRight
9595
.via(RemoveDuplicate[A]()) // Because the raft messaging might be very chatty, we want to remove duplicates
9696
.catchAll(err => ZStream.die(err))
97+
end ZmqRpc
9798

9899
object ZmqRpc:
99100
def make[A <: Command: Codec](bindAddress: String, peers: Map[MemberId, String]) =

raft/src/main/scala/zio/raft/InsertSortList.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ case class InsertSortList[A](list: List[A])(using ordering: Ordering[A]) extends
88
override def iterator: Iterator[A] = list.iterator
99

1010
def withSortedInsert(a: A): InsertSortList[A] =
11-
if (list.isEmpty || ordering.gteq(a, list.last)) then InsertSortList(list :+ a)
11+
if list.isEmpty || ordering.gteq(a, list.last) then InsertSortList(list :+ a)
1212
else
1313
val (before, after) = list.span(ordering.lteq(_, a))
1414
InsertSortList(before ++ (a :: after))

raft/src/main/scala/zio/raft/LogStore.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ trait LogStore[A <: Command]:
3333
case Some(ourTerm) if ourTerm <= term => ZIO.succeed((ourTerm, index))
3434
case Some(ourTerm) => findConflictByTerm(term, index.minusOne)
3535

36-
end LogStore
37-
3836
object LogStore:
3937
def makeInMemory[A <: Command]: ZIO[Any, Nothing, InMemoryLogStore[A]] =
4038
for logs <- Ref.make(List.empty[LogEntry[A]])

raft/src/main/scala/zio/raft/Raft.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,13 @@ class Raft[S, A <: Command](
115115
lastTerm <- logStore.lastTerm
116116
lastIndex <- logStore.lastIndex
117117
result <-
118-
if (
118+
if
119119
currentTerm == m.term && (votedFor.contains(
120120
m.candidateId
121121
) || votedFor.isEmpty) &&
122122
(m.lastLogTerm > lastTerm ||
123123
(m.lastLogTerm == lastTerm &&
124124
m.lastLogIndex >= lastIndex))
125-
)
126125
then
127126
for
128127
_ <- stable.voteFor(m.candidateId)
@@ -241,7 +240,7 @@ class Raft[S, A <: Command](
241240
else if success then
242241
for
243242
_ <- ZIO.when(m.previousIndex < lastIndex)(
244-
ZIO.foreachDiscard(m.entries)(entry => {
243+
ZIO.foreachDiscard(m.entries)(entry =>
245244
for
246245
logTerm <- logStore.logTerm(entry.index)
247246
_ <- ZIO.when(
@@ -250,7 +249,7 @@ class Raft[S, A <: Command](
250249
logStore.deleteFrom(entry.index)
251250
)
252251
yield ()
253-
})
252+
)
254253
)
255254
_ <- logStore.storeLogs(m.entries)
256255
messageLastIndex = m.entries.last.index
@@ -777,6 +776,8 @@ class Raft[S, A <: Command](
777776
)
778777
yield ()
779778
yield ()
779+
end for
780+
end sendAppendEntries
780781

781782
private def sendRequestVoteRule(peer: MemberId) =
782783
for
@@ -929,10 +930,10 @@ class Raft[S, A <: Command](
929930
// todo: leader only
930931
for
931932
promiseArg <- Promise.make[NotALeaderError, commandArg.Response]
932-
_ <- commandsQueue.offer(new CommandMessage {
933+
_ <- commandsQueue.offer(new CommandMessage:
933934
val command = commandArg
934935
val promise = promiseArg.asInstanceOf
935-
})
936+
)
936937
res <- promiseArg.await
937938
yield (res)
938939

@@ -1081,3 +1082,4 @@ object Raft:
10811082
)
10821083
_ <- raft.run.forkScoped
10831084
yield raft
1085+
end Raft

raft/src/main/scala/zio/raft/ReplicationStatus.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class ReplicationStatus(val peerStatus: Map[MemberId, PeerReplicationStatus]):
6767
peerStatus.get(peer) match
6868
case Some(PeerReplicationStatus.Snapshot(_, _)) => true
6969
case _ => false
70+
end ReplicationStatus
7071

7172
object ReplicationStatus:
7273
def apply(peers: Peers) = new ReplicationStatus(

0 commit comments

Comments
 (0)