Skip to content

Commit

Permalink
Merge pull request #447 from 47degrees/update/latest-versions
Browse files Browse the repository at this point in the history
Update plugins/dependencies to latest versions
  • Loading branch information
alejandrohdezma committed Sep 10, 2021
2 parents bc1ffbf + 0761d02 commit f531470
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 205 deletions.
1 change: 1 addition & 0 deletions .scalafmt-extra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rewrite.neverInfix.excludeFilters."+" = [ "should", "be", "must", "equalTo", "like", "and", "some", "lessThan" ]
117 changes: 73 additions & 44 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,92 @@
# To edit the original configurations go to
# https://github.com/alejandrohdezma/sbt-scalafmt-defaults/edit/master/.scalafmt.conf

version = 2.7.5
version = 3.0.2

# Number of maximum characters in a column
maxColumn = 120

newlines {
alwaysBeforeTopLevelStatements = true
sometimesBeforeColonInMethodReturnType = false
}
# Ensure newlines are added arround top level body definitions always
newlines.topLevelBodyIfMinStatements = [before,after]
newlines.topLevelBodyMinStatements = 1

# Allow line-overflow for comments and lines that would overflow even with a newline.
newlines.avoidForSimpleOverflow=[slc, tooLong]

style = defaultWithAlign
# Ensure newlines around every statement except `case object` definitions
newlines.topLevelStatementBlankLines = [
{
blanks = 1,
minBreaks = 0,
regex = "^(?!((Term\\.Apply)|(Defn\\.Object)))"
}
]

# Ensure lines starting with the margin character `|` are indented differently
assumeStandardLibraryStripMargin = true

align {
stripMargin = true
tokens.add = [
{
code = ":=", owner = "Term.ApplyInfix"
},
{
code = "+=", owner = "Term.ApplyInfix"
},
{
code = "++=", owner = "Term.ApplyInfix"
},
{
code = "--=", owner = "Term.ApplyInfix"
},
{
code = "-=", owner = "Term.ApplyInfix"
}
]
}
# Align everything that can be aligned
align.preset = most
align.multiline = false
align.tokens."+" = [
{
code = ":=", owner = "Term.ApplyInfix"
},
{
code = "+=", owner = "Term.ApplyInfix"
},
{
code = "++=", owner = "Term.ApplyInfix"
},
{
code = "--=", owner = "Term.ApplyInfix"
},
{
code = "-=", owner = "Term.ApplyInfix"
}
]

binPack {
literalArgumentLists = true
literalsIncludeSimpleExpr = true
literalsExclude = [ "Term.Name" ]
}
# Allow literal argument lists with newlines only once `maxColumn` is reached
binPack.literalArgumentLists = true
binPack.literalsIncludeSimpleExpr = true
binPack.literalsExclude = [ "Term.Name" ]

# Use ScalaDoc style and enable wrapping when reaching `maxColumn`
docstrings.style = "SpaceAsterisk"
docstrings.wrap = yes
docstrings.oneline = fold

rewrite {
rules = [
ExpandImportSelectors,
PreferCurlyFors
RedundantBraces,
RedundantParens,
SortModifiers
]
redundantBraces.maxLines = 1
redundantBraces.stringInterpolation = true
# Avoid infix calls (except for operators)
rewrite.rules += AvoidInfix

# Ensure redundant braces are removed
rewrite.rules += RedundantBraces
rewrite.redundantBraces.maxLines = 1
rewrite.redundantBraces.stringInterpolation = true

# Ensure redundant parentheses are removed
rewrite.rules += RedundantParens

# Ensure modifiers like `implicit` or `final` are sorted the same
rewrite.rules += SortModifiers

# Replaces parentheses into curly braces in for comprehensions that contain multiple enumerator generators
rewrite.rules += PreferCurlyFors

# Ensure a separate line is created for each selector within a `{...}` import.
rewrite.rules += Imports
rewrite.imports.expand = true

# Avoid ASCII tokens
rewriteTokens = {
"⇒": "=>"
"→": "->"
"←": "<-"
}

# Select followed by curly braces should not start a chain
includeCurlyBraceInSelectChains = false

includeNoParensInSelectChains = false

optIn.blankLineBeforeDocstring = true
# Ensure code blocks inside markdown files get formated too
project.includePaths."+" = ["glob:**.md"]
rewrite.neverInfix.excludeFilters."+" = [ "should", "be", "must", "equalTo", "like", "and", "some", "lessThan" ]
4 changes: 4 additions & 0 deletions bench/src/main/scala/UUIDBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ import memeid4s.UUID
import org.openjdk.jmh.annotations._

object UUIDStates {

val namespace = UUID.V1.next

@SuppressWarnings(Array("scalafix:Disable.toString"))
val uuids: Array[String] = (1 to 100).map(_ => UUID.V1.next.toString).toArray

@State(Scope.Benchmark)
class RNG {

def uuid: String = uuids(ThreadLocalRandom.current().nextInt(uuids.length))

}

}
Expand Down Expand Up @@ -72,4 +75,5 @@ class UUIDBenchmark {
@Benchmark
def fromString(x: RNG): UUID =
memeid.UUID.fromString(x.uuid)

}
28 changes: 18 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ThisBuild / scalaVersion := "2.13.3"
ThisBuild / crossScalaVersions := Seq("2.12.12", "2.13.3")
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6")
ThisBuild / organization := "com.47deg"

addCommandAlias("ci-test", "fix --check; +mdoc; testCovered")
Expand All @@ -19,14 +19,22 @@ lazy val `memeid` = module
//// SCALA ////
/////////////////

lazy val memeid4s = module.dependsOn(`memeid`, `memeid4s-scalacheck` % Test)
lazy val `memeid4s-cats` = module.dependsOn(`memeid4s`, `memeid4s-scalacheck` % Test)
lazy val `memeid4s-literal` = module.dependsOn(`memeid4s`)
lazy val `memeid4s-doobie` = module.dependsOn(`memeid4s`)
lazy val `memeid4s-circe` = module.dependsOn(`memeid4s`, `memeid4s-cats` % Test, `memeid4s-scalacheck` % Test)
lazy val `memeid4s-http4s` = module.dependsOn(`memeid4s`, `memeid4s-cats` % Test, `memeid4s-scalacheck` % Test)
lazy val `memeid4s-tapir` = module.dependsOn(`memeid4s`, `memeid4s-cats` % Test, `memeid4s-scalacheck` % Test)
lazy val `memeid4s-fuuid` = module.dependsOn(`memeid4s`, `memeid4s-scalacheck` % Test)
lazy val memeid4s = module.dependsOn(`memeid`, `memeid4s-scalacheck` % Test)

lazy val `memeid4s-cats` = module.dependsOn(`memeid4s`, `memeid4s-scalacheck` % Test)

lazy val `memeid4s-literal` = module.dependsOn(`memeid4s`)

lazy val `memeid4s-doobie` = module.dependsOn(`memeid4s`)

lazy val `memeid4s-circe` = module.dependsOn(`memeid4s`, `memeid4s-cats` % Test, `memeid4s-scalacheck` % Test)

lazy val `memeid4s-http4s` = module.dependsOn(`memeid4s`, `memeid4s-cats` % Test, `memeid4s-scalacheck` % Test)

lazy val `memeid4s-tapir` = module.dependsOn(`memeid4s`, `memeid4s-cats` % Test, `memeid4s-scalacheck` % Test)

lazy val `memeid4s-fuuid` = module.dependsOn(`memeid4s`, `memeid4s-scalacheck` % Test)

lazy val `memeid4s-scalacheck` = module.dependsOn(memeid)

/////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions modules/memeid/src/test/scala/memeid/BitsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class BitsSpec extends Specification {
}

object Cast {

def sb8(b: Long): Byte = (0x00000000000000ff & b).toByte

}

private def mask(width: Long, offset: Long): Long =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ trait instances {
override def maxBound: UUID = UUID.from(-1L, -1L)

override def partialOrder: PartialOrder[UUID] = UUIDHashOrderInstances

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ class DoobieSpec extends Specification with IOChecker with BeforeAll with IOMatc

io must returnValue(uuid)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import scala.reflect.macros.blackbox
import memeid.UUID

private[literal] class Macros(val c: blackbox.Context) {

import c.universe._

def uuidInterpolator(args: Any*): c.Expr[UUID] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object instances {
timestamp <- arbitrary[Long]
clockSequence <- arbitrary[Short]
id <- arbitrary[Long]
node = new Node(clockSequence, id)
node = new Node(clockSequence, id)
} yield UUID.V1.next(node, () => timestamp).asInstanceOf[UUID.V1]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import sttp.tapir.Codec
import sttp.tapir.CodecFormat
import sttp.tapir.DecodeResult
import sttp.tapir.Schema
import sttp.tapir.SchemaType.SString

@SuppressWarnings(Array("scalafix:DisableSyntax.valInAbstract"))
trait instances {
Expand All @@ -30,10 +29,10 @@ trait instances {
implicit val UUIDCodec: Codec[String, UUID, CodecFormat.TextPlain] =
Codec.string
.mapDecode(s => UUID.from(s).fold(DecodeResult.Error(s, _), DecodeResult.Value(_)))(_.toString) // scalafix:ok
.modifySchema(_.format("uuid"))
.schema(_.format("uuid"))

/** Provides a valid `Schema` for `UUID` type, to be used when generating documentation. */
implicit val UUIDSchema: Schema[UUID] = Schema(SString).format("uuid")
implicit val UUIDSchema: Schema[UUID] = Schema.string[UUID].format("uuid")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class InstancesSpec extends Specification with ScalaCheck {
"provide correct schema when generating documentation" in {
val testEndpoint = endpoint.get.in("hello" / path[UUID])

val result = OpenAPIDocsInterpreter.toOpenAPI(testEndpoint, "", "").toYaml
val result = OpenAPIDocsInterpreter().toOpenAPI(testEndpoint, "", "").toYaml

val expected =
"""openapi: 3.0.3
Expand All @@ -56,6 +56,12 @@ class InstancesSpec extends Specification with ScalaCheck {
| responses:
| '200':
| description: ''
| '400':
| description: 'Invalid value for: path parameter p1'
| content:
| text/plain:
| schema:
| type: string
|""".stripMargin

result must be equalTo expected
Expand Down
Loading

0 comments on commit f531470

Please sign in to comment.