Skip to content

Commit e5a094d

Browse files
committed
Add scalafmt configuration
1 parent f8280b6 commit e5a094d

File tree

8 files changed

+334
-231
lines changed

8 files changed

+334
-231
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ on:
88
pull_request:
99

1010
jobs:
11+
format:
12+
timeout-minutes: 15
13+
runs-on: ubuntu-24.04
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
submodules: true
19+
- uses: VirtusLab/scala-cli-setup@v1
20+
- run: scala-cli fmt . --check
21+
1122
test:
23+
needs: format
1224
runs-on: ubuntu-24.04
1325
strategy:
1426
fail-fast: false
@@ -27,7 +39,9 @@ jobs:
2739
run: ./mill -i 'tests.test'
2840

2941
publish:
30-
needs: test
42+
needs:
43+
- test
44+
- format
3145
runs-on: ubuntu-24.04
3246
if: github.event_name == 'push'
3347
steps:
@@ -48,7 +62,9 @@ jobs:
4862
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
4963

5064
generate-launchers:
51-
needs: test
65+
needs:
66+
- test
67+
- format
5268
runs-on: ${{ matrix.os }}
5369
strategy:
5470
fail-fast: false
@@ -91,7 +107,9 @@ jobs:
91107
UPLOAD_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92108

93109
generate-static-launcher:
94-
needs: test
110+
needs:
111+
- test
112+
- format
95113
runs-on: ubuntu-24.04
96114
strategy:
97115
fail-fast: false
@@ -124,7 +142,9 @@ jobs:
124142
UPLOAD_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125143

126144
generate-mostly-static-launcher:
127-
needs: test
145+
needs:
146+
- test
147+
- format
128148
runs-on: ubuntu-24.04
129149
strategy:
130150
fail-fast: false

.scalafmt.conf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version = "3.9.6"
2+
3+
align.preset = more
4+
maxColumn = 100
5+
assumeStandardLibraryStripMargin = true
6+
indent.defnSite = 2
7+
indentOperator.topLevelOnly = false
8+
align.preset = more
9+
align.openParenCallSite = false
10+
newlines.source = keep
11+
newlines.beforeMultiline = keep
12+
newlines.afterCurlyLambdaParams = keep
13+
newlines.alwaysBeforeElseAfterCurlyIf = true
14+
15+
runner.dialect = scala3
16+
17+
rewrite.rules = [
18+
RedundantBraces
19+
RedundantParens
20+
SortModifiers
21+
]
22+
23+
rewrite.redundantBraces {
24+
ifElseExpressions = true
25+
includeUnitMethods = false
26+
stringInterpolation = true
27+
}
28+
29+
rewrite.sortModifiers.order = [
30+
"private", "final", "override", "protected",
31+
"implicit", "sealed", "abstract", "lazy"
32+
]
33+
34+
project.excludeFilters = [
35+
".bloop"
36+
".metals"
37+
".scala-build"
38+
"examples"
39+
"out"
40+
"scala-version.scala"
41+
]

build.mill.scala

Lines changed: 80 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ import scala.concurrent.duration._
1717
import scala.util.Properties.isWin
1818

1919
object Versions {
20-
def scala213 = "2.13.16"
21-
def scalaJsVersion = "1.19.0"
22-
def jsoniterVersion = "2.35.3"
20+
def scala213 = "2.13.16"
21+
def scalaJsVersion = "1.19.0"
22+
def jsoniterVersion = "2.35.3"
2323
def scalaJsImportMapVersion = "0.1.1"
24-
def graalVmVersion = "22.3.1"
25-
def munitVersion = "1.1.1"
26-
def osLibVersion = "0.11.4"
27-
def pprintVersion = "0.9.0"
28-
def coursierVersion = "2.1.24"
29-
def scoptVersion = "4.1.0"
30-
def ubuntuVersion = "24.04"
24+
def graalVmVersion = "22.3.1"
25+
def munitVersion = "1.1.1"
26+
def osLibVersion = "0.11.4"
27+
def pprintVersion = "0.9.0"
28+
def coursierVersion = "2.1.24"
29+
def scoptVersion = "4.1.0"
30+
def ubuntuVersion = "24.04"
3131
}
3232
object cli extends Cli
3333
trait Cli extends ScalaModule with ScalaJsCliPublishModule {
@@ -58,7 +58,7 @@ trait Cli extends ScalaModule with ScalaJsCliPublishModule {
5858
def urlOf(path: os.Path): Option[String] =
5959
if (path.startsWith(cachePath)) {
6060
val segments = path.relativeTo(cachePath).segments
61-
val url = segments.head + "://" + segments.tail.mkString("/")
61+
val url = segments.head + "://" + segments.tail.mkString("/")
6262
Some(url)
6363
}
6464
else None
@@ -69,7 +69,7 @@ trait Cli extends ScalaModule with ScalaJsCliPublishModule {
6969
Parameters,
7070
Preamble
7171
}
72-
val cp = jarClassPath().map(_.path)
72+
val cp = jarClassPath().map(_.path)
7373
val mainClass0 = mainClass().getOrElse(sys.error("No main class"))
7474

7575
val dest = Task.ctx().dest / (if (isWin) "launcher.bat" else "launcher")
@@ -81,7 +81,7 @@ trait Cli extends ScalaModule with ScalaJsCliPublishModule {
8181
urlOf(path) match {
8282
case None =>
8383
val content = os.read.bytes(path)
84-
val name = path.last
84+
val name = path.last
8585
ClassPathEntry.Resource(name, os.mtime(path), content)
8686
case Some(url) => ClassPathEntry.Url(url)
8787
}
@@ -108,14 +108,14 @@ trait ScalaJsCliNativeImage extends ScalaModule with NativeImage {
108108
"--no-fallback",
109109
"-H:IncludeResources=org/scalajs/linker/backend/emitter/.*.sjsir",
110110
"-H:IncludeResources=com/google/javascript/jscomp/js/polyfills.txt",
111-
"-H:IncludeResourceBundles=com.google.javascript.jscomp.parsing.ParserConfig",
111+
"-H:IncludeResourceBundles=com.google.javascript.jscomp.parsing.ParserConfig"
112112
)
113113
}
114-
def nativeImagePersist: Boolean = System.getenv("CI") != null
115-
def graalVmVersion: String = Versions.graalVmVersion
114+
def nativeImagePersist: Boolean = System.getenv("CI") != null
115+
def graalVmVersion: String = Versions.graalVmVersion
116116
def nativeImageGraalVmJvmId: Target[String] = s"graalvm-java17:$graalVmVersion"
117-
def nativeImageName: Target[String] = "scala-js-ld"
118-
def moduleDeps: Seq[JavaModule] = Seq(cli)
117+
def nativeImageName: Target[String] = "scala-js-ld"
118+
def moduleDeps: Seq[JavaModule] = Seq(cli)
119119
def compileIvyDeps: Target[Agg[Dep]] =
120120
super.compileIvyDeps() ++ Seq(ivy"org.graalvm.nativeimage:svm:$graalVmVersion")
121121
def nativeImageMainClass: Target[String] = "org.scalajs.cli.Scalajsld"
@@ -156,10 +156,11 @@ trait ScalaJsCliStaticNativeImage extends ScalaJsCliNativeImage {
156156
)
157157
)
158158
}
159-
def writeNativeImageScript(scriptDest: String, imageDest: String = ""): Command[Unit] = Task.Command {
160-
buildHelperImage()
161-
super.writeNativeImageScript(scriptDest, imageDest)()
162-
}
159+
def writeNativeImageScript(scriptDest: String, imageDest: String = ""): Command[Unit] =
160+
Task.Command {
161+
buildHelperImage()
162+
super.writeNativeImageScript(scriptDest, imageDest)()
163+
}
163164
}
164165
object `native-static` extends ScalaJsCliStaticNativeImage
165166

@@ -189,30 +190,42 @@ object tests extends ScalaModule {
189190
override def test(args: String*): Command[(String, Seq[TestResult])] = jvm(args: _*)
190191

191192
private def testExtraArgs(launcher: os.Path): Seq[String] = Seq(
192-
s"-Dtest.scala-js-cli.path=${launcher}",
193+
s"-Dtest.scala-js-cli.path=$launcher",
193194
s"-Dtest.scala-js-cli.scala-js-version=${Versions.scalaJsVersion}"
194195
)
195196

196197
@unused
197198
def jvm(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
198-
testTask(Task.Anon { args ++ testExtraArgs(cli.standaloneLauncher().path) }, Task.Anon(Seq.empty[String]))()
199+
testTask(
200+
Task.Anon(args ++ testExtraArgs(cli.standaloneLauncher().path)),
201+
Task.Anon(Seq.empty[String])
202+
)()
199203
}
200204
@unused
201205
def native(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
202-
testTask(Task.Anon { args ++ testExtraArgs(native0.nativeImage().path) }, Task.Anon(Seq.empty[String]))()
206+
testTask(
207+
Task.Anon(args ++ testExtraArgs(native0.nativeImage().path)),
208+
Task.Anon(Seq.empty[String])
209+
)()
203210
}
204211
@unused
205212
def nativeStatic(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
206-
testTask(Task.Anon { args ++ testExtraArgs(`native-static`.nativeImage().path) }, Task.Anon(Seq.empty[String]))()
213+
testTask(
214+
Task.Anon(args ++ testExtraArgs(`native-static`.nativeImage().path)),
215+
Task.Anon(Seq.empty[String])
216+
)()
207217
}
208218
@unused
209219
def nativeMostlyStatic(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
210-
testTask(Task.Anon { args ++ testExtraArgs(`native-mostly-static`.nativeImage().path) }, Task.Anon(Seq.empty[String]))()
220+
testTask(
221+
Task.Anon(args ++ testExtraArgs(`native-mostly-static`.nativeImage().path)),
222+
Task.Anon(Seq.empty[String])
223+
)()
211224
}
212225
}
213226
}
214227

215-
def ghOrg = "virtuslab"
228+
def ghOrg = "virtuslab"
216229
def ghName = "scala-js-cli"
217230
trait ScalaJsCliPublishModule extends PublishModule {
218231
import mill.scalalib.publish._
@@ -226,7 +239,7 @@ trait ScalaJsCliPublishModule extends PublishModule {
226239
Developer("alexarchambault", "Alex Archambault", "https://github.com/alexarchambault"),
227240
Developer("sjrd", "Sébastien Doeraene", "https://github.com/sjrd"),
228241
Developer("gzm0", "Tobias Schlatter", "https://github.com/gzm0"),
229-
Developer("nicolasstucki", "Nicolas Stucki", "https://github.com/nicolasstucki"),
242+
Developer("nicolasstucki", "Nicolas Stucki", "https://github.com/nicolasstucki")
230243
)
231244
)
232245
def publishVersion: Target[String] = finalPublishVersion()
@@ -247,7 +260,8 @@ def computePublishVersion(state: VcsState, simple: Boolean): String =
247260
Some(tag.take(idx + 1) + (tag.drop(idx + 1).toInt + 1).toString + "-SNAPSHOT")
248261
else
249262
None
250-
} else {
263+
}
264+
else {
251265
val idx = tag.indexOf("-")
252266
if (idx >= 0) Some(tag.take(idx) + "+" + tag.drop(idx + 1) + "-SNAPSHOT")
253267
else None
@@ -257,7 +271,8 @@ def computePublishVersion(state: VcsState, simple: Boolean): String =
257271
Some(versionOrEmpty)
258272
.filter(_.nonEmpty)
259273
.getOrElse(state.format())
260-
} else {
274+
}
275+
else {
261276
val rawVersion = os
262277
.proc("git", "describe", "--tags")
263278
.call()
@@ -292,29 +307,30 @@ def finalPublishVersion: Target[String] = {
292307

293308
object ci extends Module {
294309
@unused
295-
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]): Command[Unit] = Task.Command {
296-
publishSonatype0(
297-
data = define.Target.sequence(tasks.value)(),
298-
log = Task.ctx().log
299-
)
300-
}
310+
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]): Command[Unit] =
311+
Task.Command {
312+
publishSonatype0(
313+
data = define.Target.sequence(tasks.value)(),
314+
log = Task.ctx().log
315+
)
316+
}
301317

302318
private def publishSonatype0(
303-
data: Seq[PublishModule.PublishData],
304-
log: mill.api.Logger
319+
data: Seq[PublishModule.PublishData],
320+
log: mill.api.Logger
305321
): Unit = {
306322

307323
val credentials = sys.env("SONATYPE_USERNAME") + ":" + sys.env("SONATYPE_PASSWORD")
308324
val pgpPassword = sys.env("PGP_PASSPHRASE")
309-
val timeout = 10.minutes
325+
val timeout = 10.minutes
310326

311327
val artifacts = data.map { case PublishModule.PublishData(a, s) =>
312328
(s.map { case (p, f) => (p.path, f) }, a)
313329
}
314330

315331
val isRelease = {
316332
val versions = artifacts.map(_._2.version).toSet
317-
val set = versions.map(!_.endsWith("-SNAPSHOT"))
333+
val set = versions.map(!_.endsWith("-SNAPSHOT"))
318334
assert(
319335
set.size == 1,
320336
s"Found both snapshot and non-snapshot versions: ${versions.toVector.sorted.mkString(", ")}"
@@ -330,8 +346,10 @@ object ci extends Module {
330346
"--detach-sign",
331347
"--batch=true",
332348
"--yes",
333-
"--pinentry-mode", "loopback",
334-
"--passphrase", pgpPassword,
349+
"--pinentry-mode",
350+
"loopback",
351+
"--passphrase",
352+
pgpPassword,
335353
"--armor",
336354
"--use-agent"
337355
),
@@ -359,8 +377,24 @@ object ci extends Module {
359377
if (version.endsWith("-SNAPSHOT")) ("launchers", true)
360378
else ("v" + version, false)
361379

362-
Upload.upload(ghOrg, ghName, ghToken, tag, dryRun = false, overwrite = overwriteAssets)(launchers: _*)
363-
if(version != Versions.scalaJsVersion && !version.endsWith("-SNAPSHOT")) // when we release `0.13.0.1` we should also update native launchers in tag `0.13.0`
364-
Upload.upload(ghOrg, ghName, ghToken, s"v${Versions.scalaJsVersion}", dryRun = false, overwrite = true)(launchers: _*)
380+
Upload.upload(
381+
ghOrg,
382+
ghName,
383+
ghToken,
384+
tag,
385+
dryRun = false,
386+
overwrite = overwriteAssets
387+
)(launchers: _*)
388+
if (
389+
version != Versions.scalaJsVersion && !version.endsWith("-SNAPSHOT")
390+
) // when we release `0.13.0.1` we should also update native launchers in tag `0.13.0`
391+
Upload.upload(
392+
ghOrg,
393+
ghName,
394+
ghToken,
395+
s"v${Versions.scalaJsVersion}",
396+
dryRun = false,
397+
overwrite = true
398+
)(launchers: _*)
365399
}
366400
}

0 commit comments

Comments
 (0)