Skip to content

Commit d152bbf

Browse files
committed
Tighten wartremover setings
1 parent c4b081a commit d152bbf

64 files changed

Lines changed: 272 additions & 195 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ ThisBuild / scalaVersion := "3.8.1"
66
ThisBuild / evictionErrorLevel := Level.Debug
77

88
ThisBuild / semanticdbEnabled := true
9-
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision
109

1110
val utils = (project in file("utils"))
1211
.settings(Settings.common)
@@ -214,5 +213,5 @@ val root = (project in file("."))
214213
`edsl`
215214
)
216215
.settings(
217-
run / aggregate := false,
216+
run / aggregate := false
218217
)

backend/circe-utils/src/main/scala/ru/tinkoff/tcb/utils/circe/optics/JsonOptic.scala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ final case class JsonOptic private[optics] (private val jsonPath: Seq[PathPart])
5050

5151
def prune: Json => Json = { json =>
5252
if (validate(json))
53-
jsonPath.init.foldRight[Json => Json] { json =>
54-
jsonPath.last.fold(
55-
f => json.withObject(jo => Json.fromJsonObject(jo.remove(f))),
56-
i => json.withArray(ja => Json.fromValues(ja.take(i) ++ ja.drop(i + 1))),
57-
if (json.isArray) Json.Null else json
58-
)
59-
}((part, f) => modifyPart(Json.Null)(part)(f))(json)
53+
jsonPath.lastOption.fold(json) { lastPart =>
54+
jsonPath
55+
.dropRight(1)
56+
.foldRight[Json => Json] { innerJson =>
57+
lastPart.fold(
58+
f => innerJson.withObject(jo => Json.fromJsonObject(jo.remove(f))),
59+
i => innerJson.withArray(ja => Json.fromValues(ja.take(i) ++ ja.drop(i + 1))),
60+
if (innerJson.isArray) Json.Null else innerJson
61+
)
62+
}((part, f) => modifyPart(Json.Null)(part)(f))(json)
63+
}
6064
else json
6165
}
6266

@@ -82,7 +86,9 @@ final case class JsonOptic private[optics] (private val jsonPath: Seq[PathPart])
8286
jsonPath.foldRight[Json => Json](op)((part, f) => modifyPart(Json.Null)(part)(f))
8387

8488
def modifyOpt(op: Option[Json] => Json): Json => Json =
85-
jsonPath.init.foldRight[Json => Json](modifyPart(jsonPath.last)(op))((part, f) => modifyPart(Json.Null)(part)(f))
89+
jsonPath.lastOption.fold[Json => Json](identity) { lastPart =>
90+
jsonPath.dropRight(1).foldRight[Json => Json](modifyPart(lastPart)(op))((part, f) => modifyPart(Json.Null)(part)(f))
91+
}
8692

8793
def modifyObjectValues(op: Json => Json): Json => Json = { json =>
8894
getOpt(json)

backend/circe-utils/src/main/scala/ru/tinkoff/tcb/utils/circe/optics/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ package object optics {
2727
else {
2828
val itemsToAdd = index - ja.length + 1
2929
Json.fromValues(
30-
ja ++ Vector.tabulate(itemsToAdd)(idx => if (idx == itemsToAdd - 1) mod(None) else Json.Null)
30+
ja ++ Vector.tabulate(itemsToAdd)(idx => if (idx === itemsToAdd - 1) mod(None) else Json.Null)
3131
)
3232
}
3333
}

backend/circe-utils/src/main/scala/ru/tinkoff/tcb/utils/circe/package.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ package object circe {
5252

5353
if (baseArr.length >= patchArr.length)
5454
Json.fromValues((baseArr zip patchArr).map(mrgPair.tupled))
55-
else Json.fromValues(baseArr.zipAll(patchArr, Json.Null, patchArr.last).map(mrgPair.tupled))
55+
else
56+
Json.fromValues(
57+
baseArr.zipAll(patchArr, Json.Null, patchArr.lastOption.getOrElse(Json.Null)).map(mrgPair.tupled)
58+
)
5659
case (p, JsonNull()) if arraySubvalues => p
5760
case (_, p) => p
5861
}

backend/circe-utils/src/test/scala/ru/tinkoff/tcb/utils/circe/optics/OpticSpec.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class OpticSpec extends RefSpec with Matchers {
150150

151151
val optic = JLens \ "value"
152152

153-
optic.modify(_.withNumber(jn => Json.fromInt(jn.toInt.get * 2)))(target) shouldBe
153+
optic.modify(_.withNumber(jn => jn.toInt.fold(Json.Null)(n => Json.fromInt(n * 2))))(target) shouldBe
154154
json"""{"value": 4}"""
155155
}
156156

@@ -159,7 +159,7 @@ class OpticSpec extends RefSpec with Matchers {
159159

160160
val optic = (JLens \ "value").traverse
161161

162-
optic.modify(_.withNumber(jn => Json.fromInt(jn.toInt.get * 2)))(target) shouldBe
162+
optic.modify(_.withNumber(jn => jn.toInt.fold(Json.Null)(n => Json.fromInt(n * 2))))(target) shouldBe
163163
json"""{"value": [2, 4, 6]}"""
164164
}
165165
}
@@ -171,7 +171,7 @@ class OpticSpec extends RefSpec with Matchers {
171171
val optic = JLens \ "value"
172172

173173
optic.modifyOpt {
174-
case Some(json) => json.withNumber(jn => Json.fromInt(jn.toInt.get * 2))
174+
case Some(json) => json.withNumber(jn => jn.toInt.fold(Json.Null)(n => Json.fromInt(n * 2)))
175175
case None => Json.fromInt(2)
176176
}(target) shouldBe
177177
json"""{"value": 4}"""
@@ -183,7 +183,7 @@ class OpticSpec extends RefSpec with Matchers {
183183
val optic = JLens \ "value"
184184

185185
optic.modifyOpt {
186-
case Some(json) => json.withNumber(jn => Json.fromInt(jn.toInt.get * 2))
186+
case Some(json) => json.withNumber(jn => jn.toInt.fold(Json.Null)(n => Json.fromInt(n * 2)))
187187
case None => Json.fromInt(2)
188188
}(target) shouldBe
189189
json"""{"value": 2}"""
@@ -196,7 +196,8 @@ class OpticSpec extends RefSpec with Matchers {
196196

197197
val optic = JLens \ "outer"
198198

199-
optic.modifyObjectValues(_.withNumber(jn => Json.fromInt(jn.toInt.get * 2)))(target) shouldBe
199+
optic
200+
.modifyObjectValues(_.withNumber(jn => jn.toInt.fold(Json.Null)(n => Json.fromInt(n * 2))))(target) shouldBe
200201
json"""{"outer": {"inner": 84}}"""
201202
}
202203
}
@@ -208,7 +209,7 @@ class OpticSpec extends RefSpec with Matchers {
208209
val optic = JLens \ "outer"
209210

210211
optic.modifyFields { case (key, value) =>
211-
key -> value.withNumber(jn => Json.fromInt(jn.toInt.get * 2))
212+
key -> value.withNumber(jn => jn.toInt.fold(Json.Null)(n => Json.fromInt(n * 2)))
212213
}(target) shouldBe json"""{"outer": {"inner": 84}}"""
213214
}
214215
}

backend/dataAccess/src/main/scala/ru/tinkoff/tcb/dataaccess/UpdateResult.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package ru.tinkoff.tcb.dataaccess
22

33
final case class UpdateResult(matched: Long, modified: Long) {
44
val successful: Boolean = matched > 0 || modified > 0
5-
val noMatch: Boolean = matched == 0
6-
val noOp: Boolean = modified == 0
5+
val noMatch: Boolean = matched === 0L
6+
val noOp: Boolean = modified === 0L
77
val unsuccessful: Boolean = noMatch && noOp
88
}
99

backend/dataAccess/src/main/scala/ru/tinkoff/tcb/generic/Fields.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object Fields extends AutoDerivation[Fields] {
3434
implicit def enumEntry[T <: EnumEntry]: Fields[T] = mk(Nil)
3535
implicit def strEnum[T <: StringEnumEntry]: Fields[T] = mk(Nil)
3636

37-
def join[T](caseClass: CaseClass[Fields, T]): Fields[T] =
37+
override def join[T](caseClass: CaseClass[Fields, T]): Fields[T] =
3838
mk(
3939
caseClass.parameters
4040
.foldLeft(List.newBuilder[String])((acc, fld) =>
@@ -44,5 +44,5 @@ object Fields extends AutoDerivation[Fields] {
4444
.result()
4545
)
4646

47-
def split[T](sealedTrait: SealedTrait[Fields, T]): Fields[T] = mk(Nil)
47+
override def split[T](sealedTrait: SealedTrait[Fields, T]): Fields[T] = mk(Nil)
4848
}

backend/dataAccess/src/main/scala/ru/tinkoff/tcb/generic/RootOptionFields.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object RootOptionFields extends AutoDerivation[RootOptionFields] {
3535
implicit def refn[T, R, F[_, _]](implicit rt: RefType[F], rof: RootOptionFields[T]): RootOptionFields[F[T, R]] =
3636
mk(rof.fields)
3737

38-
def join[T](caseClass: CaseClass[RootOptionFields, T]): RootOptionFields[T] =
38+
override def join[T](caseClass: CaseClass[RootOptionFields, T]): RootOptionFields[T] =
3939
mk(
4040
caseClass.parameters
4141
.foldLeft(Set.newBuilder[String])((acc, fld) =>
@@ -45,5 +45,5 @@ object RootOptionFields extends AutoDerivation[RootOptionFields] {
4545
.result()
4646
)
4747

48-
def split[T](sealedTrait: SealedTrait[RootOptionFields, T]): RootOptionFields[T] = mk(Set.empty)
48+
override def split[T](sealedTrait: SealedTrait[RootOptionFields, T]): RootOptionFields[T] = mk(Set.empty)
4949
}

backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/RoundRobinSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RoundRobinSpec extends AnyFunSuite with Matchers with TryValues {
1313
implicit private val regexEquality: Equality[Regex] =
1414
(a: Regex, b: Any) =>
1515
b match {
16-
case rb: Regex => a.regex == rb.regex
16+
case rb: Regex => a.regex === rb.regex
1717
case _ => false
1818
}
1919

backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/enumeratum/BsonEnumSpec.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package ru.tinkoff.tcb.bson.enumeratum
22

33
import oolong.bson.*
44
import org.mongodb.scala.bson.*
5+
import org.scalatest.TryValues
56
import org.scalatest.funspec.AnyFunSpec
67
import org.scalatest.matchers.should.Matchers
78

8-
class BsonEnumSpec extends AnyFunSpec with Matchers {
9+
class BsonEnumSpec extends AnyFunSpec with Matchers with TryValues {
910
describe("BSON serdes") {
1011

1112
describe("deserialisation") {
1213

1314
it("should work with valid values") {
1415
val bsonValue: BsonValue = BsonString("A")
15-
BsonDecoder[Dummy].fromBson(bsonValue).get shouldBe Dummy.A
16+
BsonDecoder[Dummy].fromBson(bsonValue).success.value shouldBe Dummy.A
1617
}
1718

1819
it("should fail with invalid values") {

0 commit comments

Comments
 (0)