Skip to content

Commit

Permalink
introduce code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-git committed May 8, 2024
1 parent f6535c3 commit 10b75da
Show file tree
Hide file tree
Showing 11 changed files with 560 additions and 733 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
distribution: 'oracle'
cache: 'sbt'

- name: Check code formatting
run: sbt check

- name: build ${{ matrix.scala }}
run: sbt ++${{ matrix.scala }} clean coverage test

Expand Down
6 changes: 6 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rules = [OrganizeImports]

OrganizeImports {
preset = INTELLIJ_2020_3
targetDialect = Auto
}
19 changes: 19 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version = 3.8.1

maxColumn = 120

preset = default
align.preset = none

trailingCommas = always

continuationIndent {
callSite = 2
defnSite = 2
}

rewrite.rules = [
RedundantBraces, RedundantParens, SortModifiers, prefercurlyfors
]

runner.dialect = Scala213Source3
24 changes: 18 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ organizationHomepage := Some(url("https://evolution.com"))
homepage := Some(url("https://github.com/evolution-gaming/resource-pool"))
startYear := Some(2023)

crossScalaVersions := Seq("2.13.14")
scalaVersion := crossScalaVersions.value.head
scalacOptions := Seq(
"-release:17",
"-Xsource:3",
"-deprecation",
inThisBuild(
List(
crossScalaVersions := Seq("2.13.14"),
scalaVersion := crossScalaVersions.value.head,
scalacOptions := Seq(
"-release:17",
"-Xsource:3",
"-deprecation",
"-Wunused:imports",
),
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
),
)

releaseCrossBuild := true
autoAPIMappings := true
versionScheme := Some("early-semver")
Expand All @@ -29,3 +37,7 @@ libraryDependencies ++= Seq(
licenses := Seq(("MIT", url("https://opensource.org/licenses/MIT")))

addCommandAlias("build", "all compile test")

// https://github.com/scalacenter/scalafix/issues/1488
addCommandAlias("check", "scalafixAll --check; all scalafmtCheckAll scalafmtSbtCheck")
addCommandAlias("fix", "scalafixAll; all scalafmtAll scalafmtSbt")
6 changes: 3 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sbt._

object Dependencies {
val scalatest = "org.scalatest" %% "scalatest" % "3.2.18" % Test
val `kind-projector` = "org.typelevel" % "kind-projector" % "0.13.3"
val `cats-effect` = "org.typelevel" %% "cats-effect" % "3.5.4"
val scalatest = "org.scalatest" %% "scalatest" % "3.2.18" % Test
val `kind-projector` = "org.typelevel" % "kind-projector" % "0.13.3"
val `cats-effect` = "org.typelevel" %% "cats-effect" % "3.5.4"
}
6 changes: 5 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0")

addSbtPlugin("com.evolution" % "sbt-scalac-opts-plugin" % "0.0.9")

addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")
addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
10 changes: 3 additions & 7 deletions src/main/scala/com/evolution/resourcepool/IntHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@ private[resourcepool] object IntHelper {

implicit class IntOpsIntHelper(val self: Int) extends AnyVal {

def divide(value: Int): List[Int] = {
def divide(value: Int): List[Int] =
if (value <= 0 || self <= 0) {
List.empty
} else if (value >= self) {
List.fill(self)(1)
} else if (value == 1) {
List(self)
} else {
val quotient = (self.toDouble / value)
.round
.toInt
val quotient = (self.toDouble / value).round.toInt

@tailrec
def loop(self: Int, value: Int, result: List[Int]): List[Int] = {
def loop(self: Int, value: Int, result: List[Int]): List[Int] =
if (self > quotient && value > 1) {
loop(self - quotient, value - 1, quotient :: result)
} else {
(self :: result).reverse
}
}

loop(self, value, List.empty)
}
}
}
}
Loading

0 comments on commit 10b75da

Please sign in to comment.