Skip to content

Commit

Permalink
Add and apply scalafmt (#154)
Browse files Browse the repository at this point in the history
* Add scalafmt

* Apply scalafmt
  • Loading branch information
mdedetrich authored Jul 13, 2021
1 parent 68ad186 commit 13d8365
Show file tree
Hide file tree
Showing 55 changed files with 594 additions and 467 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Scalafmt

on:
pull_request:
branches: ['**']

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Code is formatted
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Check project is formatted
uses: jrouly/scalafmt-native-action@v1
with:
version: '2.7.5'
9 changes: 9 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version = 2.7.5
preset = default
align.preset = most
maxColumn = 120
project.git = true
align.tokens.add = [
{code = ":=", owner = "Term.ApplyInfix"}
]
rewrite.rules = [RedundantBraces, RedundantParens]
109 changes: 57 additions & 52 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import sbtrelease.Version


val gc = TaskKey[Unit]("gc", "runs garbage collector")
val gc = TaskKey[Unit]("gc", "runs garbage collector")
lazy val gcTask = gc := {
println("requesting garbage collection")
System gc()
System gc ()
}

ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("mimaReportBinaryIssues"),
name = Some("Report binary compatibility issues")),
WorkflowStep.Sbt(List("clean", "coverage","test"),
name = Some("Build project"))
WorkflowStep.Sbt(List("mimaReportBinaryIssues"), name = Some("Report binary compatibility issues")),
WorkflowStep.Sbt(List("clean", "coverage", "test"), name = Some("Build project"))
)

ThisBuild / githubWorkflowBuildPostamble ++= Seq(
// See https://github.com/scoverage/sbt-coveralls#github-actions-integration
WorkflowStep.Sbt(List("coverageReport", "coveralls"),
WorkflowStep.Sbt(
List("coverageReport", "coveralls"),
name = Some("Upload coverage data to Coveralls"),
env = Map(
"COVERALLS_REPO_TOKEN" -> "${{ secrets.GITHUB_TOKEN }}",
"COVERALLS_FLAG_NAME" -> "Scala ${{ matrix.scala }}"
"COVERALLS_FLAG_NAME" -> "Scala ${{ matrix.scala }}"
)
)
)
Expand All @@ -32,31 +30,39 @@ ThisBuild / githubWorkflowUseSbtThinClient := false
ThisBuild / githubWorkflowPublishTargetBranches := Seq()

ThisBuild / crossScalaVersions := Seq("2.10.7", "2.11.12", "2.13.6", "2.12.14")
ThisBuild / scalaVersion := (ThisBuild / crossScalaVersions).value.last
ThisBuild / scalaVersion := (ThisBuild / crossScalaVersions).value.last

// Coveralls doesn't really work with Scala 2.10.7 so we are disabling it for CI
ThisBuild / githubWorkflowScalaVersions -= "2.10.7"

lazy val root = project.in(file("."))
lazy val root = project
.in(file("."))
.settings(
/* basic project info */
name := "ficus",
description := "A Scala-friendly wrapper companion for Typesafe config",
startYear := Some(2013),
name := "ficus",
description := "A Scala-friendly wrapper companion for Typesafe config",
startYear := Some(2013),
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-unchecked",
"-encoding", "UTF-8",
"-encoding",
"UTF-8",
"-target:jvm-1." + {
CrossVersion.partialVersion(scalaVersion.value).collect {
case (2, minor) if minor <= 10 & scalaVersion.value == "2.10.7" => "8"
case (2, minor) if minor <= 10 => "7"
}.getOrElse("8")
CrossVersion
.partialVersion(scalaVersion.value)
.collect {
case (2, minor) if minor <= 10 & scalaVersion.value == "2.10.7" => "8"
case (2, minor) if minor <= 10 => "7"
}
.getOrElse("8")
}
) ++ (if (scalaVersion.value.startsWith("2.11") || scalaVersion.value.startsWith("2.10")) Seq("-Yclosure-elim", "-Yinline") else Seq.empty[String]),
) ++ (if (scalaVersion.value.startsWith("2.11") || scalaVersion.value.startsWith("2.10"))
Seq("-Yclosure-elim", "-Yinline")
else Seq.empty[String]),
javacOptions ++= Seq(
"-Xlint:unchecked", "-Xlint:deprecation"
"-Xlint:unchecked",
"-Xlint:deprecation"
),
Compile / unmanagedSourceDirectories ++= {
(Compile / unmanagedSourceDirectories).value.map { dir =>
Expand All @@ -70,54 +76,53 @@ lazy val root = project.in(file("."))
(Test / unmanagedSourceDirectories).value.map { dir =>
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => file(dir.getPath ++ "-2.13+")
case _ => file(dir.getPath ++ "-2.13-")
case _ => file(dir.getPath ++ "-2.13-")
}
}
},
libraryDependencies ++=
(if (scalaVersion.value.startsWith("2.10"))
Seq(
"org.specs2" %% "specs2-core" % "3.10.0" % Test,
"org.specs2" %% "specs2-scalacheck" % "3.10.0" % Test)
else
Seq(
"org.specs2" %% "specs2-core" % "4.8.3" % Test,
"org.specs2" %% "specs2-scalacheck" % "4.8.3" % Test)) ++
Seq(
"org.scalacheck" %% "scalacheck" % "1.14.1" % Test,
"com.chuusai" %% "shapeless" % "2.3.3" % Test,
"com.typesafe" % "config" % "1.3.4",
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided) ++
(if (!scalaVersion.value.startsWith("2.13"))
Seq(
compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full),
"org.typelevel" %% "macro-compat" % "1.1.1")
Seq("org.specs2" %% "specs2-core" % "3.10.0" % Test, "org.specs2" %% "specs2-scalacheck" % "3.10.0" % Test)
else
Seq.empty[ModuleID]),
Seq("org.specs2" %% "specs2-core" % "4.8.3" % Test, "org.specs2" %% "specs2-scalacheck" % "4.8.3" % Test)) ++
Seq(
"org.scalacheck" %% "scalacheck" % "1.14.1" % Test,
"com.chuusai" %% "shapeless" % "2.3.3" % Test,
"com.typesafe" % "config" % "1.3.4",
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided
) ++
(if (!scalaVersion.value.startsWith("2.13"))
Seq(
compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full),
"org.typelevel" %% "macro-compat" % "1.1.1"
)
else
Seq.empty[ModuleID]),
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Resolver.bintrayRepo("iheartradio","maven"),
Resolver.bintrayRepo("iheartradio", "maven"),
Resolver.jcenterRepo
),
Test / parallelExecution := true,
Test / parallelExecution := true,
/* sbt behavior */
compile / logLevel := Level.Warn,
traceLevel := 5,
offline := false,
compile / logLevel := Level.Warn,
traceLevel := 5,
offline := false,
Compile / packageBin / mappings := {
val ms = (Compile / packageBin / mappings).value
ms filter { case (_, toPath) =>
toPath != "application.conf"
}
},
Publish.settings,
releaseCrossBuild := true,
mimaPreviousArtifacts :=
Version(version.value).collect {
case Version(major, (minor :: bugfix :: _), _) if (scalaBinaryVersion.value != "2.10") && bugfix > 0 =>
Set(organization.value %% name.value % Seq(major, minor, bugfix - 1).mkString("."))
}.getOrElse(Set.empty),

releaseCrossBuild := true,
mimaPreviousArtifacts :=
Version(version.value)
.collect {
case Version(major, (minor :: bugfix :: _), _) if (scalaBinaryVersion.value != "2.10") && bugfix > 0 =>
Set(organization.value %% name.value % Seq(major, minor, bugfix - 1).mkString("."))
}
.getOrElse(Set.empty),
gcTask
)
42 changes: 20 additions & 22 deletions project/Publish.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import com.jsuereth.sbtpgp.PgpKeys
import sbtrelease.ReleasePlugin.autoImport._
import sbtrelease.ReleaseStateTransformations._


object Publish {

pomExtra in Global := {

<developers>
<developers>
<developer>
<id>ceedubs</id>
<name>Cody Allen</name>
Expand All @@ -23,27 +22,28 @@ object Publish {
</developers>
}


val publishingSettings = Seq(

ThisBuild / organization := "com.iheart",
publishMavenStyle := true,
licenses := Seq("MIT" -> url("http://www.opensource.org/licenses/mit-license.html")),
homepage := Some(url("http://iheartradio.github.io/ficus")),
scmInfo := Some(ScmInfo(
url("https://github.com/iheartradio/ficus"),
"git@github.com:iheartradio/ficus.git",
Some("git@github.com:iheartradio/ficus.git"))),
pomIncludeRepository := { _ => false },
Test / publishArtifact := false,
publishTo := {
ThisBuild / organization := "com.iheart",
publishMavenStyle := true,
licenses := Seq("MIT" -> url("http://www.opensource.org/licenses/mit-license.html")),
homepage := Some(url("http://iheartradio.github.io/ficus")),
scmInfo := Some(
ScmInfo(
url("https://github.com/iheartradio/ficus"),
"git@github.com:iheartradio/ficus.git",
Some("git@github.com:iheartradio/ficus.git")
)
),
pomIncludeRepository := { _ => false },
Test / publishArtifact := false,
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("Snapshots" at nexus + "content/repositories/snapshots")
else
Some("Releases" at nexus + "service/local/staging/deploy/maven2")
},
pomExtra := (
},
pomExtra := (
<developers>
<developer>
<id>ceedubs</id>
Expand All @@ -56,11 +56,10 @@ object Publish {
<email>kailuo.wang@gmail.com</email>
</developer>
</developers>
),
releaseCrossBuild := true,
),
releaseCrossBuild := true,
releasePublishArtifactsAction := PgpKeys.publishSigned.value,

releaseProcess := Seq[ReleaseStep](
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
Expand All @@ -74,7 +73,6 @@ object Publish {
ReleaseStep(action = Command.process("sonatypeReleaseAll", _)),
pushChanges
)

)

val settings = publishingSettings
Expand Down
19 changes: 7 additions & 12 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
resolvers += "Typesafe Repository" at "https://repo.typesafe.com/typesafe/releases/"

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.8.2")

addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")

addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.9.2")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.7")

addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.8.2")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.9.2")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.7")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.12.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ trait CollectionReaders {

private[this] val DummyPathValue: String = "collection-entry-path"

implicit def traversableReader[C[_], A](implicit entryReader: ValueReader[A], cbf: Factory[A, C[A]]): ValueReader[C[A]] = new ValueReader[C[A]] {
implicit def traversableReader[C[_], A](implicit
entryReader: ValueReader[A],
cbf: Factory[A, C[A]]
): ValueReader[C[A]] = new ValueReader[C[A]] {
def read(config: Config, path: String): C[A] = {
val list = config.getList(path).asScala
val list = config.getList(path).asScala
val builder = cbf.newBuilder
builder.sizeHint(list.size)
list foreach { entry =>
Expand All @@ -24,15 +27,16 @@ trait CollectionReaders {
}
}

implicit def mapValueReader[A](implicit entryReader: ValueReader[A]): ValueReader[Map[String, A]] = new ValueReader[Map[String, A]] {
def read(config: Config, path: String): Map[String, A] = {
val relativeConfig = config.getConfig(path)
relativeConfig.root().entrySet().asScala map { entry =>
val key = entry.getKey
key -> entryReader.read(relativeConfig, ConfigUtil.quoteString(key))
} toMap
implicit def mapValueReader[A](implicit entryReader: ValueReader[A]): ValueReader[Map[String, A]] =
new ValueReader[Map[String, A]] {
def read(config: Config, path: String): Map[String, A] = {
val relativeConfig = config.getConfig(path)
relativeConfig.root().entrySet().asScala map { entry =>
val key = entry.getKey
key -> entryReader.read(relativeConfig, ConfigUtil.quoteString(key))
} toMap
}
}
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ trait CollectionReaders {

private[this] val DummyPathValue: String = "collection-entry-path"

implicit def traversableReader[C[_], A](implicit entryReader: ValueReader[A], cbf: CanBuildFrom[Nothing, A, C[A]]): ValueReader[C[A]] = new ValueReader[C[A]] {
implicit def traversableReader[C[_], A](implicit
entryReader: ValueReader[A],
cbf: CanBuildFrom[Nothing, A, C[A]]
): ValueReader[C[A]] = new ValueReader[C[A]] {
def read(config: Config, path: String): C[A] = {
val list = config.getList(path).asScala
val list = config.getList(path).asScala
val builder = cbf()
builder.sizeHint(list.size)
list foreach { entry =>
Expand All @@ -23,15 +26,16 @@ trait CollectionReaders {
}
}

implicit def mapValueReader[A](implicit entryReader: ValueReader[A]): ValueReader[Map[String, A]] = new ValueReader[Map[String, A]] {
def read(config: Config, path: String): Map[String, A] = {
val relativeConfig = config.getConfig(path)
relativeConfig.root().entrySet().asScala map { entry =>
val key = entry.getKey
key -> entryReader.read(relativeConfig, ConfigUtil.quoteString(key))
} toMap
implicit def mapValueReader[A](implicit entryReader: ValueReader[A]): ValueReader[Map[String, A]] =
new ValueReader[Map[String, A]] {
def read(config: Config, path: String): Map[String, A] = {
val relativeConfig = config.getConfig(path)
relativeConfig.root().entrySet().asScala map { entry =>
val key = entry.getKey
key -> entryReader.read(relativeConfig, ConfigUtil.quoteString(key))
} toMap
}
}
}

}

Expand Down
Loading

0 comments on commit 13d8365

Please sign in to comment.