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

Set up scalafmt #3231

Merged
merged 3 commits into from
Nov 30, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Initial applied scalafmtAll and scalafmtSbt
c1a068b59a36f88401ea646577e4ed61df1e1b4a
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: lint

on:
pull_request:
paths-ignore:
- 'doc/**'
- 'docs/**'
- '*.md'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: checkout the repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11

- name: run lint
run: sbt -v "+scalafmtCheckAll;scalafmtSbtCheck"
13 changes: 13 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version = 3.8.3

align.preset = most
literals.double = Upper
literals.float = Upper
maxColumn = 120
newlines.source = keep
rewriteTokens = {
"⇒": "=>"
"→": "->"
"←": "<-"
}
runner.dialect = scala213
139 changes: 73 additions & 66 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ def isGithubActions = sys.env.getOrElse("CI", "false") == "true"

// set by github actions when executing a release build
def releaseVersion: String = sys.env.getOrElse("RELEASE_VERSION", "")
def isRelease = releaseVersion != ""
def isRelease = releaseVersion != ""

// set by github actions and used as the snapshot build number
def githubRunNumber = sys.env.getOrElse("GITHUB_RUN_NUMBER", "local")

val scala2Versions = Seq("2.12.20", "2.13.15")
val scala2Versions = Seq("2.12.20", "2.13.15")
val scalaAllVersions = scala2Versions :+ "3.3.4"

lazy val commonScalaVersionSettings = Seq(
scalaVersion := "2.12.20",
scalaVersion := "2.12.20",
crossScalaVersions := Nil
)

Expand All @@ -28,13 +28,13 @@ lazy val warnUnusedImport = Seq(
Compile / console / scalacOptions ~= {
_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-unused:imports"))
},
Test / console / scalacOptions := (Compile / console / scalacOptions).value,
Test / console / scalacOptions := (Compile / console / scalacOptions).value
)

lazy val commonSettings = Seq(
organization := "nl.gn0s1s",
organization := "nl.gn0s1s",
resolvers += Resolver.mavenLocal,
Test / parallelExecution := false,
Test / parallelExecution := false,
Compile / doc / scalacOptions := (Compile / doc / scalacOptions).value.filter(_ != "-Xfatal-warnings"),
scalacOptions ++= Seq("-unchecked", "-deprecation", "-encoding", "utf8")
)
Expand All @@ -44,19 +44,19 @@ lazy val publishSettings = Seq(
)

lazy val commonJvmSettings = Seq(
Test / testOptions += {
Test / testOptions += {
val flag = if (isGithubActions) "-oCI" else "-oDF"
Tests.Argument(TestFrameworks.ScalaTest, flag)
},
Test / fork := true,
Test / fork := true,
Test / javaOptions := Seq("-Xmx3G"),
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
javaOptions ++= Seq("-Xms512M", "-Xmx2048M", "-XX:+CMSClassUnloadingEnabled"),
javaOptions ++= Seq("-Xms512M", "-Xmx2048M", "-XX:+CMSClassUnloadingEnabled")
)

lazy val pomSettings = Seq(
startYear := Some(2013),
homepage := Some(url("https://github.com/philippus/elastic4s")),
startYear := Some(2013),
homepage := Some(url("https://github.com/philippus/elastic4s")),
licenses += License.Apache2,
developers := List(
Developer(
Expand All @@ -75,12 +75,11 @@ lazy val pomSettings = Seq(
)

lazy val noPublishSettings = Seq(
publish := {},
publishLocal := {},
publish := {},
publishLocal := {},
publishArtifact := false
)


lazy val allSettings = commonScalaVersionSettings ++
commonJvmSettings ++
commonSettings ++
Expand All @@ -93,35 +92,35 @@ lazy val scala2Settings = allSettings :+ (crossScalaVersions := scala2Versions)
lazy val scala3Settings = allSettings :+ (crossScalaVersions := scalaAllVersions)

lazy val scala3Projects: Seq[ProjectReference] = Seq(
json_builder,
domain,
handlers,
core,
clientcore,
clientesjava,
clientsSniffed,
clientpekko,
clienthttp4s,
cats_effect,
cats_effect_2,
zio_1,
zio,
monix,
tests,
testkit,
circe,
jackson,
json4s,
playjson,
ziojson,
clientsttp,
httpstreams,
akkastreams,
pekkostreams,
reactivestreamsakka,
reactivestreamspekko
json_builder,
domain,
handlers,
core,
clientcore,
clientesjava,
clientsSniffed,
clientpekko,
clienthttp4s,
cats_effect,
cats_effect_2,
zio_1,
zio,
monix,
tests,
testkit,
circe,
jackson,
json4s,
playjson,
ziojson,
clientsttp,
httpstreams,
akkastreams,
pekkostreams,
reactivestreamsakka,
reactivestreamspekko
)
lazy val scala3_root = Project("elastic4s-scala3", file("scala3"))
lazy val scala3_root = Project("elastic4s-scala3", file("scala3"))
.settings(name := "elastic4s")
.settings(allSettings)
.settings(
Expand All @@ -130,7 +129,7 @@ lazy val scala3_root = Project("elastic4s-scala3", file("scala3"))
.aggregate(
scala3Projects: _*
)
lazy val root = Project("elastic4s", file("."))
lazy val root = Project("elastic4s", file("."))
.settings(name := "elastic4s")
.settings(allSettings)
.settings(
Expand Down Expand Up @@ -174,11 +173,15 @@ lazy val clientesjava = (project in file("elastic4s-client-esjava"))
.dependsOn(core)
.settings(scala3Settings)
.settings(
libraryDependencies ++= Seq(elasticsearchRestClient,
libraryDependencies ++= Seq(
elasticsearchRestClient,
log4jApi,
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion exclude("org.scala-lang", "scala-library")
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion exclude (
"org.scala-lang",
"scala-library"
)
)
)

Expand Down Expand Up @@ -240,8 +243,7 @@ lazy val httpstreams = (project in file("elastic4s-http-streams"))
Dependencies.akkaStream,
Dependencies.reactiveStreamsTck,
Dependencies.scalaTestPlusTestng
)
)
))

lazy val reactivestreamsakka = (project in file("elastic4s-reactivestreams-akka"))
.dependsOn(core, testkit % "test", jackson % "test")
Expand All @@ -253,8 +255,7 @@ lazy val reactivestreamsakka = (project in file("elastic4s-reactivestreams-akka"
Dependencies.akkaStream,
Dependencies.reactiveStreamsTck,
Dependencies.scalaTestPlusTestng
)
)
))

lazy val reactivestreamspekko = (project in file("elastic4s-reactivestreams-pekko"))
.dependsOn(core, testkit % "test", jackson % "test")
Expand All @@ -266,8 +267,7 @@ lazy val reactivestreamspekko = (project in file("elastic4s-reactivestreams-pekk
Dependencies.pekkoStream,
Dependencies.reactiveStreamsTck,
Dependencies.scalaTestPlusTestng
)
)
))

lazy val akkastreams = (project in file("elastic4s-streams-akka"))
.dependsOn(core, testkit % "test", jackson % "test")
Expand All @@ -286,9 +286,12 @@ lazy val jackson = (project in file("elastic4s-json-jackson"))
.settings(name := "elastic4s-json-jackson")
.settings(scala3Settings)
.settings(
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion exclude("org.scala-lang", "scala-library")
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion exclude (
"org.scala-lang",
"scala-library"
)
)

lazy val circe = (project in file("elastic4s-json-circe"))
Expand Down Expand Up @@ -336,7 +339,9 @@ lazy val clientsttp = (project in file("elastic4s-client-sttp"))
lazy val clientakka = (project in file("elastic4s-client-akka"))
.dependsOn(core, testkit % Test)
.settings(name := "elastic4s-client-akka")
.settings(scala2Settings) // We need akka-http to be cross-published, which depends on an akka bump with restrictive licensing changes
.settings(
scala2Settings
) // We need akka-http to be cross-published, which depends on an akka bump with restrictive licensing changes
.settings(libraryDependencies ++= Seq(akkaHTTP, akkaStream))

lazy val clientpekko = (project in file("elastic4s-client-pekko"))
Expand All @@ -351,7 +356,6 @@ lazy val clienthttp4s = (project in file("elastic4s-client-http4s"))
.settings(scala3Settings)
.settings(libraryDependencies ++= Seq(http4sClient, http4sEmberClient % Test))


lazy val tests = (project in file("elastic4s-tests"))
.settings(name := "elastic4s-tests")
.dependsOn(core, jackson, testkit % Test)
Expand All @@ -361,14 +365,17 @@ lazy val tests = (project in file("elastic4s-tests"))
libraryDependencies ++= Seq(
commonsIo,
mockitoCore,
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion % Test,
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion % Test,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion % Test exclude("org.scala-lang", "scala-library"),
"org.apache.logging.log4j" % "log4j-api" % "2.24.2" % Test,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.24.2" % Test,
"org.apache.logging.log4j" % "log4j-core" % "2.24.2" % Test
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion % Test,
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion % Test,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion % Test exclude (
"org.scala-lang",
"scala-library"
),
"org.apache.logging.log4j" % "log4j-api" % "2.24.2" % Test,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.24.2" % Test,
"org.apache.logging.log4j" % "log4j-core" % "2.24.2" % Test
),
Test / fork := false,
Test / parallelExecution := false,
Test / fork := false,
Test / parallelExecution := false,
Test / testForkedParallel := false
)
Loading