Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve linting #42

Merged
merged 9 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ jobs:
runs-on: ubuntu-latest

env:
SBT_OPTS: "-Xms6g -Xmx6g -XX:+AlwaysPreTouch -XX:ReservedCodeCacheSize=192M -XX:MaxMetaspaceSize=512M -Xss2m -XX:+TieredCompilation -XX:+UseParallelGC"
SBT_OPTS: >
-Xms6g
-Xmx6g
-XX:+AlwaysPreTouch
-XX:ReservedCodeCacheSize=192M
-Xss2m
-XX:+TieredCompilation
-XX:+UseParallelGC

steps:
- uses: actions/checkout@v4
Expand All @@ -81,7 +88,14 @@ jobs:
runs-on: ubuntu-latest

env:
SBT_OPTS: "-Xms2048m -Xmx2048m -XX:+AlwaysPreTouch -XX:ReservedCodeCacheSize=192M -XX:MaxMetaspaceSize=512M -Xss2m -XX:+TieredCompilation -XX:+UseParallelGC"
SBT_OPTS: >
-Xms2048m
-Xmx2048m
-XX:+AlwaysPreTouch
-XX:ReservedCodeCacheSize=256M
-Xss2m
-XX:+TieredCompilation
-XX:+UseParallelGC

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -161,7 +175,14 @@ jobs:

env:
CI: true
SBT_OPTS: "-Xms1024m -Xmx1024m -XX:+AlwaysPreTouch -XX:ReservedCodeCacheSize=192M -XX:MaxMetaspaceSize=512M -Xss2m -XX:+TieredCompilation -XX:+UseParallelGC"
SBT_OPTS: >
-Xms1024m
-Xmx1024m
-XX:+AlwaysPreTouch
-XX:ReservedCodeCacheSize=192M
-Xss2m
-XX:+TieredCompilation
-XX:+UseParallelGC

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -193,10 +214,15 @@ jobs:
ref: ${{ github.ref }}
head_ref: ${{ github.head_ref }}

- name: Compile and test
- name: Lint and Test
run: |
cd backend
sbt "project mockingbird-native;clean;fixCheck;test"

- name: Create native image and stage image contents
run: |
cd backend
sbt "project mockingbird-native;clean;fixCheck;test;GraalVMNativeImage / packageBin;Docker / stage;"
sbt "project mockingbird-native;GraalVMNativeImage / packageBin;Docker / stage;"

- name: Build docker image for test
uses: docker/build-push-action@v3
Expand Down
27 changes: 20 additions & 7 deletions backend/.scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ rules = [
LeakingImplicitClassVal,
NoValInForComprehension,
ProcedureSyntax
DisableSyntax
DisableSyntax,
OrganizeImports
]

RemoveUnused.imports = true
RemoveUnused.privates = false
RemoveUnused.locals = false
RemoveUnused.patternvars = false
RemoveUnused.params = false
RemoveUnused {
imports = false
privates = false
locals = false
patternvars = false
params = false
}

DisableSyntax.regex = [
{
Expand Down Expand Up @@ -37,4 +40,14 @@ DisableSyntax.regex = [
pattern = "Instant.now"
message = "Use ZIO.clockWith(_.instant)"
}
]
]

OrganizeImports {
groups = [
"re:(javax?|scala)\\.",
"*",
"ru.tinkoff."
]
expandRelative = true
importsOrder = SymbolsFirst
}
8 changes: 0 additions & 8 deletions backend/.scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@ optIn.configStyleArguments = true
project.git = true
rewrite.rules = [
PreferCurlyFors
Imports, // Может делать ошибки если есть относительные пути. Конфликтует с OrganizeImports из scalafix, но работает значительно быстрее и подхватывается Idea.
RedundantBraces
RedundantParens
SortModifiers
]
rewrite.imports.expand = true
rewrite.imports.sort = ascii
rewrite.imports.groups = [
["javax?..*", "scala..*"]
[".*", "ru\\.tinkoff.tschema\\..*", "ru\\.tinkoff.tofu\\..*"]
["ru\\.tinkoff\\..*"]
]
rewrite.sortModifiers.order = [
implicit
final
Expand Down
5 changes: 5 additions & 0 deletions backend/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ 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)

ThisBuild / evictionErrorLevel := Level.Debug

ThisBuild / semanticdbEnabled := true

val utils = (project in file("utils"))
.settings(Settings.common)
.settings(
Expand Down Expand Up @@ -209,6 +213,7 @@ val examples = (project in file("examples"))
)

val root = (project in file("."))
.disablePlugins(ContribWarts)
.aggregate(
utils,
circeUtils,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ final case class JsonOptic private[optics] (private val jsonPath: Seq[PathPart])

def getOpt: Json => Option[Json] = getAll.andThen {
case Vector() => None
case Vector(j) => Some(j)
case v => Some(Json.fromValues(v))
case Vector(j) => Option(j)
case v => Option(Json.fromValues(v))
}

def get: Json => Json = getOpt.andThen(_.getOrElse(Json.Null))
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -18,8 +19,8 @@ sealed trait BsonValueEnum[ValueType, EntryType <: ValueEnumEntry[ValueType]] {
trait IntBsonValueEnum[EntryType <: IntEnumEntry] extends BsonValueEnum[Int, EntryType] {
this: IntEnum[EntryType] =>

implicit def bsonEncoder: BsonEncoder[EntryType] = EnumHandler.writer(this)
implicit def bsonDecoder: BsonDecoder[EntryType] = EnumHandler.reader(this)
implicit override def bsonEncoder: BsonEncoder[EntryType] = EnumHandler.writer(this)
implicit override def bsonDecoder: BsonDecoder[EntryType] = EnumHandler.reader(this)
}

/**
Expand All @@ -28,8 +29,8 @@ trait IntBsonValueEnum[EntryType <: IntEnumEntry] extends BsonValueEnum[Int, Ent
trait LongBsonValueEnum[EntryType <: LongEnumEntry] extends BsonValueEnum[Long, EntryType] {
this: LongEnum[EntryType] =>

implicit def bsonEncoder: BsonEncoder[EntryType] = EnumHandler.writer(this)
implicit def bsonDecoder: BsonDecoder[EntryType] = EnumHandler.reader(this)
implicit override def bsonEncoder: BsonEncoder[EntryType] = EnumHandler.writer(this)
implicit override def bsonDecoder: BsonDecoder[EntryType] = EnumHandler.reader(this)
}

/*
Expand All @@ -50,10 +51,10 @@ trait LongBsonValueEnum[EntryType <: LongEnumEntry] extends BsonValueEnum[Long,
trait StringBsonValueEnum[EntryType <: StringEnumEntry] extends BsonValueEnum[String, EntryType] {
this: StringEnum[EntryType] =>

implicit def bsonEncoder: BsonEncoder[EntryType] = EnumHandler.writer(this)
implicit def bsonDecoder: BsonDecoder[EntryType] = EnumHandler.reader(this)
implicit def bsonKeyEncoder: BsonKeyEncoder[EntryType] = (t: EntryType) => t.value
implicit def bsonKeyDecoder: BsonKeyDecoder[EntryType] = (value: String) => Try(withValue(value))
implicit override def bsonEncoder: BsonEncoder[EntryType] = EnumHandler.writer(this)
implicit override def bsonDecoder: BsonDecoder[EntryType] = EnumHandler.reader(this)
implicit def bsonKeyEncoder: BsonKeyEncoder[EntryType] = (t: EntryType) => t.value
implicit def bsonKeyDecoder: BsonKeyDecoder[EntryType] = (value: String) => Try(withValue(value))
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import org.scalatest.TryValues
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

import ru.tinkoff.tcb.bson.BsonEncoder.ops.*
import ru.tinkoff.tcb.bson.{TestEntity => _, _}
import ru.tinkoff.tcb.bson.BsonEncoder.ops.*

class BsonDecoderSpec extends AnyFunSuite with Matchers with TryValues {
test("decode XXXCaseClass") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import org.scalactic.Prettifier
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

import ru.tinkoff.tcb.bson.BsonEncoder.ops.*
import ru.tinkoff.tcb.bson.{TestEntity as _, *}
import ru.tinkoff.tcb.bson.BsonEncoder.ops.*

class BsonWriterSpec extends AnyFunSuite with Matchers {
@nowarn("cat=unused-privates")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class DerivedCodecsSuite extends AnyFunSuite with Checkers with Matchers with Tr
// Stolen from http://github.com/travisbrown/circe
@derive(bsonDecoder, bsonEncoder) @BsonDiscriminator("case", _.reverse)
sealed trait RecursiveAdtExample
case class BaseAdtExample(a: String) extends RecursiveAdtExample
case class NestedAdtExample(r: RecursiveAdtExample) extends RecursiveAdtExample
final case class BaseAdtExample(a: String) extends RecursiveAdtExample
final case class NestedAdtExample(r: RecursiveAdtExample) extends RecursiveAdtExample
object RecursiveAdtExample

private def atDepth(depth: Int): Gen[RecursiveAdtExample] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class FieldsSpec extends AnyFunSuite with Matchers {
}

sealed trait ST
case class A(a: Int) extends ST
case class B(b: Int) extends ST
final case class A(a: Int) extends ST
final case class B(b: Int) extends ST

test("Fields of sealed trait") {
Fields[ST].fields shouldBe Nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package ru.tinkoff.tcb.mockingbird

import scalapb.zio_grpc.RequestContext
import scalapb.zio_grpc.server.ZServerCallHandler

import com.linecorp.armeria.client.ClientFactory
import com.linecorp.armeria.client.WebClient
import com.linecorp.armeria.client.encoding.DecodingClient
Expand All @@ -13,6 +10,8 @@ import org.mongodb.scala.MongoClient
import org.mongodb.scala.MongoCollection
import org.mongodb.scala.MongoDatabase
import org.mongodb.scala.bson.BsonDocument
import scalapb.zio_grpc.RequestContext
import scalapb.zio_grpc.server.ZServerCallHandler
import sttp.client4.BackendOptions as SttpBackendOptions
import sttp.client4.armeria.zio.ArmeriaZioBackend
import tofu.logging.Logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ package object bson {

private[this] lazy val jsonFolder: Json.Folder[Either[Throwable, BsonValue]] =
new Json.Folder[Either[Throwable, BsonValue]] { self =>
final val onNull: Either[Throwable, BsonValue] = Right(BsonNull())
final def onBoolean(value: Boolean): Either[Throwable, BsonValue] = Right(BsonBoolean(value))
final def onNumber(value: JsonNumber): Either[Throwable, BsonValue] = {
final override val onNull: Either[Throwable, BsonValue] = Right(BsonNull())
final override def onBoolean(value: Boolean): Either[Throwable, BsonValue] = Right(BsonBoolean(value))
final override def onNumber(value: JsonNumber): Either[Throwable, BsonValue] = {
val asDouble = value.toDouble

if (java.lang.Double.compare(asDouble, -0.0) == 0) {
Expand All @@ -77,12 +77,12 @@ package object bson {
}
}
}
final def onString(value: String): Either[Throwable, BsonValue] = Right(BsonString(value))
final def onArray(value: Vector[Json]): Either[Throwable, BsonValue] =
final override def onString(value: String): Either[Throwable, BsonValue] = Right(BsonString(value))
final override def onArray(value: Vector[Json]): Either[Throwable, BsonValue] =
value
.traverse(json => json.foldWith(self))
.map(BsonArray.fromIterable(_))
final def onObject(value: JsonObject): Either[Throwable, BsonValue] =
final override def onObject(value: JsonObject): Either[Throwable, BsonValue] =
(value.toVector)
.traverse {
case (key, JsonDocument(json)) if json.contains("$date") =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import io.circe.parser.parse
import io.circe.syntax.*
import io.estatico.newtype.ops.*
import mouse.option.*
import sttp.client4.circe.*
import sttp.client4.{Backend as SttpBackend, *}
import sttp.client4.circe.*
import sttp.model.Method
import zio.interop.catz.core.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ru.tinkoff.tcb.mockingbird.api

import java.util.UUID
import scalapb.zio_grpc.SafeMetadata

import io.grpc.Metadata
import mouse.option.*
import scalapb.zio_grpc.SafeMetadata
import sttp.model.Header
import zio.interop.catz.*

Expand Down
Loading
Loading