From 14a30455b65c16bfeb8acb42e0b056d11f368910 Mon Sep 17 00:00:00 2001 From: Daniel Slapman Date: Sat, 3 Feb 2024 22:59:28 +0100 Subject: [PATCH] Enable wartremover --- backend/build.sbt | 2 ++ .../tcb/bson/DeserializationError.scala | 2 +- .../enumeratum/values/BsonValueEnum.scala | 3 ++- .../scala/ru/tinkoff/tcb/criteria/Term.scala | 2 +- .../tinkoff/tcb/bson/PatchGeneratorSpec.scala | 2 +- .../tcb/bson/derivation/TestDomain.scala | 10 +++++----- .../tcb/bson/derivation/XXXCaseClass.scala | 2 +- .../tcb/criteria/UpdateExpressionSpec.scala | 2 +- ...reateDestinationConfigurationRequest.scala | 2 +- .../api/request/CreateGrpcStubRequest.scala | 2 +- .../api/request/CreateScenarioRequest.scala | 2 +- .../api/request/CreateServiceRequest.scala | 2 +- .../CreateSourceConfigurationRequest.scala | 2 +- .../api/request/CreateStubRequest.scala | 2 +- ...pdateDestinationConfigurationRequest.scala | 2 +- .../api/request/UpdateScenarioRequest.scala | 4 ++-- .../UpdateSourceConfigurationRequest.scala | 2 +- .../api/request/UpdateStubRequest.scala | 4 ++-- .../api/request/XPathTestRequest.scala | 2 +- .../api/response/DestinationDTO.scala | 2 +- .../mockingbird/api/response/SourceDTO.scala | 2 +- .../mockingbird/config/Configuration.scala | 20 +++++++++---------- .../tcb/mockingbird/error/CompoundError.scala | 2 +- .../tinkoff/tcb/mockingbird/grpc/Method.scala | 2 +- .../grpc/UniversalHandlerRegistry.scala | 4 ++-- .../tcb/mockingbird/model/Callback.scala | 4 ++-- .../mockingbird/model/CallbackRequest.scala | 8 ++++---- .../model/DestinationConfiguration.scala | 2 +- .../tcb/mockingbird/model/Extractor.scala | 4 ++-- .../tcb/mockingbird/model/GrpcSchema.scala | 10 +++++----- .../tcb/mockingbird/model/GrpcStub.scala | 2 +- .../tinkoff/tcb/mockingbird/model/Label.scala | 2 +- .../tcb/mockingbird/model/Scenario.scala | 2 +- .../tcb/mockingbird/model/Service.scala | 2 +- .../tcb/mockingbird/stream/EventSpawner.scala | 4 ++-- .../PredicateConstructionError.scala | 6 +++--- backend/project/Settings.scala | 8 ++++++++ backend/project/plugins.sbt | 19 +++++++++--------- 38 files changed, 84 insertions(+), 72 deletions(-) diff --git a/backend/build.sbt b/backend/build.sbt index e0503a1d..d8be92ae 100644 --- a/backend/build.sbt +++ b/backend/build.sbt @@ -2,6 +2,8 @@ import ProjectKeys._ import ch.epfl.scala.sbtmissinglink.MissingLinkPlugin.missinglinkConflictsTag import sbt.Keys.concurrentRestrictions +ThisBuild / scalaVersion := "2.13.12" + ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value) ThisBuild / concurrentRestrictions += Tags.limit(missinglinkConflictsTag, 1) diff --git a/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/bson/DeserializationError.scala b/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/bson/DeserializationError.scala index 9830d399..f1c83729 100644 --- a/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/bson/DeserializationError.scala +++ b/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/bson/DeserializationError.scala @@ -1,6 +1,6 @@ package ru.tinkoff.tcb.bson -case class DeserializationError(message: String, cause: Throwable) extends RuntimeException(message, cause) { +final case class DeserializationError(message: String, cause: Throwable) extends RuntimeException(message, cause) { def this(message: String) = this(message, null) } object DeserializationError { diff --git a/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/bson/enumeratum/values/BsonValueEnum.scala b/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/bson/enumeratum/values/BsonValueEnum.scala index c4cb8cf0..d33fdee9 100644 --- a/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/bson/enumeratum/values/BsonValueEnum.scala +++ b/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/bson/enumeratum/values/BsonValueEnum.scala @@ -5,7 +5,8 @@ import scala.util.Try import enumeratum.values.* import ru.tinkoff.tcb.bson.* -sealed trait BsonValueEnum[ValueType, EntryType <: ValueEnumEntry[ValueType]] { + +trait BsonValueEnum[ValueType, EntryType <: ValueEnumEntry[ValueType]] { enum: ValueEnum[ValueType, EntryType] => implicit def bsonEncoder: BsonEncoder[EntryType] diff --git a/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/criteria/Term.scala b/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/criteria/Term.scala index dbd9e6a5..fe51a03f 100644 --- a/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/criteria/Term.scala +++ b/backend/dataAccess/src/main/scala/ru/tinkoff/tcb/criteria/Term.scala @@ -298,7 +298,7 @@ sealed trait RegexModifier { def value: String } -case class CombinedRegexModifier(lhs: RegexModifier, rhs: RegexModifier) extends RegexModifier { +final case class CombinedRegexModifier(lhs: RegexModifier, rhs: RegexModifier) extends RegexModifier { override def value: String = lhs.value + rhs.value } diff --git a/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/PatchGeneratorSpec.scala b/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/PatchGeneratorSpec.scala index 42812417..8a9ac12b 100644 --- a/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/PatchGeneratorSpec.scala +++ b/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/PatchGeneratorSpec.scala @@ -9,7 +9,7 @@ import ru.tinkoff.tcb.bson.derivation.bsonDecoder import ru.tinkoff.tcb.bson.derivation.bsonEncoder @derive(bsonEncoder, bsonDecoder) -case class TestEntity(_id: String, name: String, externalKey: Option[Int]) +final case class TestEntity(_id: String, name: String, externalKey: Option[Int]) class PatchGeneratorSpec extends AnyFunSuite with Matchers { test("Generate update with Some") { diff --git a/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/derivation/TestDomain.scala b/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/derivation/TestDomain.scala index eee91d65..142ed767 100644 --- a/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/derivation/TestDomain.scala +++ b/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/derivation/TestDomain.scala @@ -8,13 +8,13 @@ import derevo.derive import ru.tinkoff.tcb.bson.annotation.BsonKey @derive(bsonDecoder, bsonEncoder) -case class TestMeta(time: Instant, seq: Long, flag: Boolean) +final case class TestMeta(time: Instant, seq: Long, flag: Boolean) @derive(bsonDecoder, bsonEncoder) -case class TestCheck(year: Year, comment: String) +final case class TestCheck(year: Year, comment: String) @derive(bsonDecoder, bsonEncoder) -case class TestEntity( +final case class TestEntity( @BsonKey("_id") id: Int, name: String, meta: TestMeta, @@ -24,10 +24,10 @@ case class TestEntity( ) @derive(bsonDecoder, bsonEncoder) -case class TestContainer[T](value: Option[T]) +final case class TestContainer[T](value: Option[T]) @derive(bsonDecoder, bsonEncoder) -case class TestEntityWithDefaults( +final case class TestEntityWithDefaults( @BsonKey("_id") id: Int, name: String = "test", meta: TestMeta, diff --git a/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/derivation/XXXCaseClass.scala b/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/derivation/XXXCaseClass.scala index 159de383..0a863eab 100644 --- a/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/derivation/XXXCaseClass.scala +++ b/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/bson/derivation/XXXCaseClass.scala @@ -3,7 +3,7 @@ package ru.tinkoff.tcb.bson.derivation import derevo.derive @derive(bsonDecoder, bsonEncoder) -case class XXXCaseClass( +final case class XXXCaseClass( a: Int, b: Int, c: Int, diff --git a/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/criteria/UpdateExpressionSpec.scala b/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/criteria/UpdateExpressionSpec.scala index d31d13c7..bf0ed3e7 100644 --- a/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/criteria/UpdateExpressionSpec.scala +++ b/backend/dataAccess/src/test/scala/ru/tinkoff/tcb/criteria/UpdateExpressionSpec.scala @@ -9,7 +9,7 @@ import ru.tinkoff.tcb.bson.* import ru.tinkoff.tcb.bson.derivation.* import ru.tinkoff.tcb.criteria.Typed.* -case class Data(intField: Int, optField: Option[Int]) +final case class Data(intField: Int, optField: Option[Int]) object Data { implicit val dataDecoder: BsonDecoder[Data] = DerivedDecoder.genBsonDecoder[Data] diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateDestinationConfigurationRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateDestinationConfigurationRequest.scala index 73671981..3b8e6a9f 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateDestinationConfigurationRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateDestinationConfigurationRequest.scala @@ -15,7 +15,7 @@ import ru.tinkoff.tcb.protocol.schema.* import ru.tinkoff.tcb.utils.id.SID @derive(decoder, encoder, schema) -case class CreateDestinationConfigurationRequest( +final case class CreateDestinationConfigurationRequest( @description("Уникальное название конфигурации") name: SID[DestinationConfiguration], @description("Описание конфигурации") diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateGrpcStubRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateGrpcStubRequest.scala index cbd02e7d..6815a15d 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateGrpcStubRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateGrpcStubRequest.scala @@ -22,7 +22,7 @@ import ru.tinkoff.tcb.protocol.schema.* import ru.tinkoff.tcb.utils.circe.optics.JsonOptic @derive(decoder, encoder, schema) -case class CreateGrpcStubRequest( +final case class CreateGrpcStubRequest( scope: Scope, times: Option[Int Refined NonNegative] = Some(1), service: String Refined NonEmpty, diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateScenarioRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateScenarioRequest.scala index 177f25ee..89121820 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateScenarioRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateScenarioRequest.scala @@ -28,7 +28,7 @@ import ru.tinkoff.tcb.utils.circe.optics.JsonOptic import ru.tinkoff.tcb.utils.id.SID @derive(decoder, encoder, schema) -case class CreateScenarioRequest( +final case class CreateScenarioRequest( @description("Тип конфигурации") scope: Scope, @description("Количество возможных срабатываний. Имеет смысл только для scope=countdown") diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateServiceRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateServiceRequest.scala index c5c19f22..cc287283 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateServiceRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateServiceRequest.scala @@ -15,7 +15,7 @@ import ru.tinkoff.tcb.generic.PropSubset import ru.tinkoff.tcb.mockingbird.model.Service @derive(decoder, encoder, schema) -case class CreateServiceRequest( +final case class CreateServiceRequest( suffix: String Refined And[NonEmpty, MatchesRegex["[\\w-]+"]], name: String Refined NonEmpty ) diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateSourceConfigurationRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateSourceConfigurationRequest.scala index 19141fb4..26ef473c 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateSourceConfigurationRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateSourceConfigurationRequest.scala @@ -16,7 +16,7 @@ import ru.tinkoff.tcb.protocol.schema.* import ru.tinkoff.tcb.utils.id.SID @derive(decoder, encoder, schema) -case class CreateSourceConfigurationRequest( +final case class CreateSourceConfigurationRequest( @description("Уникальное название конфигурации") name: SID[SourceConfiguration], @description("Описание конфигурации") diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateStubRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateStubRequest.scala index cc2ac1d2..6fff036d 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateStubRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/CreateStubRequest.scala @@ -28,7 +28,7 @@ import ru.tinkoff.tcb.protocol.schema.* import ru.tinkoff.tcb.utils.circe.optics.JsonOptic @derive(encoder, decoder, schema) -case class CreateStubRequest( +final case class CreateStubRequest( @description("Тип конфигурации") scope: Scope, @description("Количество возможных срабатываний. Имеет смысл только для scope=countdown") diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateDestinationConfigurationRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateDestinationConfigurationRequest.scala index 370d28d5..380394cd 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateDestinationConfigurationRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateDestinationConfigurationRequest.scala @@ -14,7 +14,7 @@ import ru.tinkoff.tcb.mockingbird.model.ResourceRequest import ru.tinkoff.tcb.protocol.schema.* @derive(decoder, encoder, schema) -case class UpdateDestinationConfigurationRequest( +final case class UpdateDestinationConfigurationRequest( @description("Описание конфигурации") description: String, service: String, diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateScenarioRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateScenarioRequest.scala index 1b07608e..c80ba9c6 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateScenarioRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateScenarioRequest.scala @@ -32,7 +32,7 @@ import ru.tinkoff.tcb.utils.circe.optics.JsonOptic import ru.tinkoff.tcb.utils.id.SID @derive(decoder, encoder, schema) -case class UpdateScenarioRequest( +final case class UpdateScenarioRequest( @description("Тип конфигурации") scope: Scope, @description("Количество возможных срабатываний. Имеет смысл только для scope=countdown") @@ -63,7 +63,7 @@ object UpdateScenarioRequest { } @derive(bsonEncoder) -case class ScenarioPatch( +final case class ScenarioPatch( @BsonKey("_id") id: SID[Scenario], scope: Scope, times: Option[Int Refined NonNegative], diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateSourceConfigurationRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateSourceConfigurationRequest.scala index a90fdc53..349a89bb 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateSourceConfigurationRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateSourceConfigurationRequest.scala @@ -15,7 +15,7 @@ import ru.tinkoff.tcb.mockingbird.model.SourceConfiguration import ru.tinkoff.tcb.protocol.schema.* @derive(decoder, encoder, schema) -case class UpdateSourceConfigurationRequest( +final case class UpdateSourceConfigurationRequest( @description("Описание конфигурации") description: String, service: String, diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateStubRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateStubRequest.scala index 9d17dd6a..da8639ad 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateStubRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/UpdateStubRequest.scala @@ -33,7 +33,7 @@ import ru.tinkoff.tcb.utils.circe.optics.JsonOptic import ru.tinkoff.tcb.utils.id.SID @derive(decoder, encoder, schema) -case class UpdateStubRequest( +final case class UpdateStubRequest( @description("Тип конфигурации") scope: Scope, @description("Количество возможных срабатываний. Имеет смысл только для scope=countdown") @@ -64,7 +64,7 @@ object UpdateStubRequest { } @derive(bsonEncoder) -case class StubPatch( +final case class StubPatch( @BsonKey("_id") id: SID[HttpStub], scope: Scope, times: Option[Int Refined NonNegative], diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/XPathTestRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/XPathTestRequest.scala index 879d553a..b5f7d578 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/XPathTestRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/request/XPathTestRequest.scala @@ -9,4 +9,4 @@ import ru.tinkoff.tcb.utils.xml.XMLString import ru.tinkoff.tcb.xpath.Xpath @derive(decoder, encoder, schema) -case class XPathTestRequest(xml: XMLString, path: Xpath) +final case class XPathTestRequest(xml: XMLString, path: Xpath) diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/response/DestinationDTO.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/response/DestinationDTO.scala index 777d0921..727deccd 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/response/DestinationDTO.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/response/DestinationDTO.scala @@ -11,4 +11,4 @@ import ru.tinkoff.tcb.mockingbird.model.DestinationConfiguration import ru.tinkoff.tcb.utils.id.SID @derive(encoder, decoder, schema, bsonDecoder) -case class DestinationDTO(@BsonKey("_id") name: SID[DestinationConfiguration], description: String) +final case class DestinationDTO(@BsonKey("_id") name: SID[DestinationConfiguration], description: String) diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/response/SourceDTO.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/response/SourceDTO.scala index f86046c5..7a7f14eb 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/response/SourceDTO.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/api/response/SourceDTO.scala @@ -11,4 +11,4 @@ import ru.tinkoff.tcb.mockingbird.model.SourceConfiguration import ru.tinkoff.tcb.utils.id.SID @derive(encoder, decoder, schema, bsonDecoder) -case class SourceDTO(@BsonKey("_id") name: SID[SourceConfiguration], description: String) +final case class SourceDTO(@BsonKey("_id") name: SID[SourceConfiguration], description: String) diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/config/Configuration.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/config/Configuration.scala index 564540b9..198de8c1 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/config/Configuration.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/config/Configuration.scala @@ -8,18 +8,18 @@ import net.ceedubs.ficus.Ficus.* import net.ceedubs.ficus.readers.ArbitraryTypeReader.* import net.ceedubs.ficus.readers.EnumerationReader.* -case class ServerConfig(interface: String, port: Int, allowedOrigins: Seq[String], healthCheckRoute: Option[String]) +final case class ServerConfig(interface: String, port: Int, allowedOrigins: Seq[String], healthCheckRoute: Option[String]) -case class SecurityConfig(secret: String) +final case class SecurityConfig(secret: String) -case class ProxyServerAuth(user: String, password: String) +final case class ProxyServerAuth(user: String, password: String) object ProxyServerType extends Enumeration { val Http = Value("http") val Socks = Value("socks") } -case class ProxyServerConfig( +final case class ProxyServerConfig( `type`: ProxyServerType.Value, host: String, port: Int, @@ -28,7 +28,7 @@ case class ProxyServerConfig( auth: Option[ProxyServerAuth] ) -case class ProxyConfig( +final case class ProxyConfig( excludedRequestHeaders: Seq[String], excludedResponseHeaders: Set[String], proxyServer: Option[ProxyServerConfig], @@ -36,11 +36,11 @@ case class ProxyConfig( logOutgoingRequests: Boolean ) -case class EventConfig(fetchInterval: FiniteDuration, reloadInterval: FiniteDuration) +final case class EventConfig(fetchInterval: FiniteDuration, reloadInterval: FiniteDuration) -case class MongoConfig(uri: String, collections: MongoCollections) +final case class MongoConfig(uri: String, collections: MongoCollections) -case class MongoCollections( +final case class MongoCollections( stub: String, state: String, scenario: String, @@ -51,13 +51,13 @@ case class MongoCollections( destination: String ) -case class TracingConfig( +final case class TracingConfig( required: List[String] = List.empty, incomingHeaders: Map[String, String] = Map.empty, outcomingHeaders: Map[String, String] = Map.empty, ) -case class MockingbirdConfiguration( +final case class MockingbirdConfiguration( server: ServerConfig, security: SecurityConfig, mongo: MongoConfig, diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/error/CompoundError.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/error/CompoundError.scala index 46eb64f8..b5be6664 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/error/CompoundError.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/error/CompoundError.scala @@ -1,3 +1,3 @@ package ru.tinkoff.tcb.mockingbird.error -case class CompoundError(excs: List[Throwable]) extends Exception +final case class CompoundError(excs: List[Throwable]) extends Exception diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/grpc/Method.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/grpc/Method.scala index 027edc3c..50fbc39d 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/grpc/Method.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/grpc/Method.scala @@ -11,7 +11,7 @@ object Method { /* Универсальный маршаллер, который не меняет поток байтов */ - case class ByteMarshaller() extends Marshaller[Array[Byte]] { + final case class ByteMarshaller() extends Marshaller[Array[Byte]] { override def stream(value: Array[Byte]): InputStream = new ByteArrayInputStream(value) override def parse(stream: InputStream): Array[Byte] = stream.readAllBytes() diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/grpc/UniversalHandlerRegistry.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/grpc/UniversalHandlerRegistry.scala index ec14c3fc..001b3ce5 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/grpc/UniversalHandlerRegistry.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/grpc/UniversalHandlerRegistry.scala @@ -4,13 +4,13 @@ import io.grpc.HandlerRegistry import io.grpc.ServerCallHandler import io.grpc.ServerMethodDefinition -case class UniversalHandlerRegistry0(method: ServerMethodDefinition[?, ?]) extends HandlerRegistry { +final case class UniversalHandlerRegistry0(method: ServerMethodDefinition[?, ?]) extends HandlerRegistry { override def lookupMethod(methodName: String, authority: String): ServerMethodDefinition[?, ?] = method } -case class UniversalHandlerRegistry(handler: ServerCallHandler[Array[Byte], Array[Byte]]) extends HandlerRegistry { +final case class UniversalHandlerRegistry(handler: ServerCallHandler[Array[Byte], Array[Byte]]) extends HandlerRegistry { override def lookupMethod(methodName: String, authority: String): ServerMethodDefinition[Array[Byte], Array[Byte]] = { val methodNameArray = methodName.split("/") diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Callback.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Callback.scala index 8176d99e..446d94c6 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Callback.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Callback.scala @@ -44,7 +44,7 @@ object Callback { } @derive(decoder, encoder) -case class MessageCallback( +final case class MessageCallback( destination: SID[DestinationConfiguration], output: ScenarioOutput, callback: Option[Callback], @@ -52,7 +52,7 @@ case class MessageCallback( ) extends Callback @derive(decoder, encoder) -case class HttpCallback( +final case class HttpCallback( request: CallbackRequest, responseMode: Option[CallbackResponseMode], persist: Option[Map[JsonOptic, Json]], diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/CallbackRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/CallbackRequest.scala index b7f8124c..82f0495a 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/CallbackRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/CallbackRequest.scala @@ -49,14 +49,14 @@ object CallbackRequest { } @derive(decoder, encoder) -case class CallbackRequestWithoutBody( +final case class CallbackRequestWithoutBody( url: String Refined NonEmpty, method: HttpMethod, headers: Map[String, String] ) extends CallbackRequest @derive(decoder, encoder) -case class RawCallbackRequest( +final case class RawCallbackRequest( url: String Refined NonEmpty, method: HttpMethod, headers: Map[String, String], @@ -64,7 +64,7 @@ case class RawCallbackRequest( ) extends CallbackRequest @derive(decoder, encoder) -case class JsonCallbackRequest( +final case class JsonCallbackRequest( url: String Refined NonEmpty, method: HttpMethod, headers: Map[String, String], @@ -72,7 +72,7 @@ case class JsonCallbackRequest( ) extends CallbackRequest @derive(decoder, encoder) -case class XMLCallbackRequest( +final case class XMLCallbackRequest( url: String Refined NonEmpty, method: HttpMethod, headers: Map[String, String], diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/DestinationConfiguration.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/DestinationConfiguration.scala index 5fa0a647..cb8dbd3c 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/DestinationConfiguration.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/DestinationConfiguration.scala @@ -19,7 +19,7 @@ import ru.tinkoff.tcb.utils.crypto.AES import ru.tinkoff.tcb.utils.id.SID @derive(encoder, decoder, schema) -case class DestinationConfiguration( +final case class DestinationConfiguration( @BsonKey("_id") name: SID[DestinationConfiguration], created: Instant, description: String, diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Extractor.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Extractor.scala index 5bbdc915..5fd38845 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Extractor.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Extractor.scala @@ -48,7 +48,7 @@ object XmlExtractor { * Путь внутри CDATA */ @derive(decoder, encoder) -case class XMLCDataExtractor(prefix: Xpath, path: Xpath) extends XmlExtractor { +final case class XMLCDataExtractor(prefix: Xpath, path: Xpath) extends XmlExtractor { def apply(node: Node): Either[XPathError, Json] = node .evalXPath[String](prefix.toXPathExpr) @@ -64,7 +64,7 @@ case class XMLCDataExtractor(prefix: Xpath, path: Xpath) extends XmlExtractor { * Путь внутри CDATA */ @derive(decoder, encoder) -case class JsonCDataExtractor(prefix: Xpath, path: JsonOptic) extends XmlExtractor { +final case class JsonCDataExtractor(prefix: Xpath, path: JsonOptic) extends XmlExtractor { def apply(node: Node): Either[XPathError, Json] = node.evalXPath[Json](prefix.toXPathExpr).map(path.get) } diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/GrpcSchema.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/GrpcSchema.scala index 3a726697..75d9f260 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/GrpcSchema.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/GrpcSchema.scala @@ -49,7 +49,7 @@ object GrpcLabel } @derive(encoder, decoder, bsonDecoder, bsonEncoder, schema) -case class GrpcField( +final case class GrpcField( typ: GrpcType, label: GrpcLabel, typeName: String, @@ -101,7 +101,7 @@ object GrpcSchema { } @derive(encoder, decoder) -case class GrpcMessageSchema( +final case class GrpcMessageSchema( name: String, fields: List[GrpcField], oneofs: Option[List[GrpcOneOfSchema]] = None, @@ -116,19 +116,19 @@ object GrpcMessageSchema { } @derive(encoder, decoder, bsonEncoder, bsonDecoder, schema) -case class GrpcEnumSchema( +final case class GrpcEnumSchema( name: String, values: Map[FieldName, FieldNumber] ) extends GrpcRootMessage @derive(encoder, decoder, bsonDecoder, bsonEncoder, schema) -case class GrpcOneOfSchema( +final case class GrpcOneOfSchema( name: String, options: List[GrpcField] ) extends GrpcSchema @derive(encoder, decoder, bsonDecoder, bsonEncoder, schema) -case class GrpcProtoDefinition( +final case class GrpcProtoDefinition( name: String, schemas: List[GrpcRootMessage], `package`: Option[String] = None diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/GrpcStub.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/GrpcStub.scala index 056d8b0c..979a3228 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/GrpcStub.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/GrpcStub.scala @@ -31,7 +31,7 @@ import ru.tinkoff.tcb.utils.id.SID import ru.tinkoff.tcb.validation.Rule @derive(bsonDecoder, bsonEncoder, decoder, encoder, schema) -case class GrpcStub( +final case class GrpcStub( @BsonKey("_id") id: SID[GrpcStub], scope: Scope, created: Instant, diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Label.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Label.scala index c1fefba1..b5e0f93d 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Label.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Label.scala @@ -8,7 +8,7 @@ import ru.tinkoff.tcb.bson.derivation.bsonEncoder import ru.tinkoff.tcb.utils.id.SID @derive(bsonDecoder, bsonEncoder) -case class Label( +final case class Label( @BsonKey("_id") id: SID[Label], serviceSuffix: String, label: String diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Scenario.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Scenario.scala index 2855d6a1..1ac74e59 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Scenario.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Scenario.scala @@ -30,7 +30,7 @@ import ru.tinkoff.tcb.utils.unpack.* import ru.tinkoff.tcb.validation.Rule @derive(bsonDecoder, bsonEncoder, encoder, decoder, schema) -case class Scenario( +final case class Scenario( @BsonKey("_id") @description("id мока") id: SID[Scenario], diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Service.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Service.scala index b721cdb6..580b6fe5 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Service.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/Service.scala @@ -10,4 +10,4 @@ import ru.tinkoff.tcb.bson.derivation.bsonDecoder import ru.tinkoff.tcb.bson.derivation.bsonEncoder @derive(bsonDecoder, bsonEncoder, encoder, decoder, schema) -case class Service(@BsonKey("_id") suffix: String, name: String) +final case class Service(@BsonKey("_id") suffix: String, name: String) diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/stream/EventSpawner.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/stream/EventSpawner.scala index 2b528c1c..c9456429 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/stream/EventSpawner.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/stream/EventSpawner.scala @@ -85,7 +85,7 @@ final class EventSpawner( reInit = triggers.exists(sp => sp.code.forall(_ == response.code.code) && sp.checkBody(response.body.merge)) body <- ZIO .fromEither(response.body) - .mapError(err => + .mapError[Exception](err => (if (reInit) SourceFault(_) else EventProcessingError(_))( s"Запрос на ${req.url.asString} завершился ошибкой ($err)" ) @@ -110,7 +110,7 @@ final class EventSpawner( (for { _ <- Tracing.init res <- fetch(sourceConf.request, sourceConf.reInitTriggers.map(_.toVector).orEmpty) - .mapError(SpawnError(sourceConf.name, _)) + .mapError[Exception](SpawnError(sourceConf.name, _)) neRes = res.filter(_.nonEmpty) _ <- ZIO.when(neRes.nonEmpty)(log.info(s"Отправлено в обработку: ${neRes.length}")) _ <- ZIO diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/PredicateConstructionError.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/PredicateConstructionError.scala index 51bc1e54..23794c11 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/PredicateConstructionError.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/PredicateConstructionError.scala @@ -30,8 +30,8 @@ object PredicateConstructionError { } } -case class XPathError(xpath: String, error: String) extends PredicateConstructionError -case class SpecificationError(xpath: String, errors: NonEmptyList[(Keyword, Json)]) extends PredicateConstructionError +final case class XPathError(xpath: String, error: String) extends PredicateConstructionError +final case class SpecificationError(xpath: String, errors: NonEmptyList[(Keyword, Json)]) extends PredicateConstructionError -case class JSpecificationError(optic: JsonOptic, errors: NonEmptyList[(Keyword, Json)]) +final case class JSpecificationError(optic: JsonOptic, errors: NonEmptyList[(Keyword, Json)]) extends PredicateConstructionError diff --git a/backend/project/Settings.scala b/backend/project/Settings.scala index 6d1509e0..1f2c6a37 100644 --- a/backend/project/Settings.scala +++ b/backend/project/Settings.scala @@ -8,6 +8,7 @@ import com.typesafe.sbt.packager.docker._ import com.typesafe.sbt.packager.linux.LinuxPlugin.autoImport._ import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.Universal import coursierapi.{MavenRepository => CoursierMvnRepo} +import wartremover.WartRemover.autoImport._ import sbt.Keys._ import sbt._ @@ -66,6 +67,13 @@ object Settings { ), addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"), addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.13.2" cross CrossVersion.full), + wartremoverDependencies += "org.wartremover" % "sbt-wartremover-contrib" % "2.1.0" extra("sbtVersion" -> "1.0", "scalaVersion" -> "2.12"), + wartremoverErrors ++= Seq( + Wart.ExplicitImplicitTypes, + Wart.FinalCaseClass, + //Wart.IterableOps, + Wart.LeakingSealed + ), missinglinkExcludedDependencies ++= Seq( moduleFilter(organization = "ch.qos.logback", name = "logback-core" | "logback-classic"), // missinglink некорректно обрабатывает scope optional diff --git a/backend/project/plugins.sbt b/backend/project/plugins.sbt index 0923ba21..a13f1e0e 100644 --- a/backend/project/plugins.sbt +++ b/backend/project/plugins.sbt @@ -1,13 +1,14 @@ addDependencyTreePlugin -addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") -addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") -addSbtPlugin("ch.epfl.scala" % "sbt-missinglink" % "0.3.6") -addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6") -addSbtPlugin("org.scalameta" % "sbt-native-image" % "0.3.4") -addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1") +addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") +addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") +addSbtPlugin("ch.epfl.scala" % "sbt-missinglink" % "0.3.6") +addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6") +addSbtPlugin("org.scalameta" % "sbt-native-image" % "0.3.4") +addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1") +addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.6") libraryDependencies += "com.thesamet.scalapb.zio-grpc" %% "zio-grpc-codegen" % "0.6.0-test8"