Skip to content

Commit 4e5a8f8

Browse files
Format code with scalafmt + test format via travis
1 parent 93d3d66 commit 4e5a8f8

8 files changed

+110
-39
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ target/
1313
/bin/
1414
/.cache-main
1515
/.cache-tests
16+
admin/.coursier
17+
admin/.scalafmt*

.scalafmt.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
align = more
2+
docstrings = JavaDoc
3+
assumeStandardLibraryStripMargin = true
4+
project.git = true
5+
maxColumn = 100
6+
project.excludeFilters = [
7+
"scalafix/input/"
8+
"scalafix/output/"
9+
"scalafix/output212/"
10+
"scalafix/output212\\+/"
11+
"scalafix/output213/"
12+
"scalafix/output213-failure/"
13+
]
14+
15+

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ matrix:
5959
scala: 2.12.6
6060
env: TEST_BINARY_COMPAT=true
6161

62+
# # run scalafmt
63+
# - jdk: oraclejdk8
64+
# scala: 2.12.6
65+
# env: TEST_SCALAFMT=true
66+
6267
# | jdk | scala | scala target | scala target version | scalafix test |
6368
# | ----------- | --------- | ------------ | -------------------- |---------------|
6469
# | openjdk6 | 2.11.12 | jvm | | |

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class ToIteratorVsIteratorSrc(xs: Iterable[Int]) {
5353
- run sbt
5454
and then run the following task `compile`;
5555

56-
5. Commit your changes, push your branch to your fork and create a pull request.
56+
5. Format your code with the `scalafmt` sbt task.
57+
58+
6. Commit your changes, push your branch to your fork and create a pull request.
5759

5860
Then maybe someone will take over and implement your use case… or maybe you will
5961
(see next section)!

admin/install-scalafmt-githook.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# set -x
4+
5+
HERE="`dirname $0`"
6+
DST="$HERE/../.git/hooks/pre-commit"
7+
8+
if [ ! -f $DST ]; then
9+
cp "$HERE/pre-commit" $DST
10+
fi

admin/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
$GIT_DIR/../admin/scalafmt.sh --test $GIT_DIR/..

admin/scalafmt.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
# set -x
4+
5+
HERE="`dirname $0`"
6+
VERSION="1.5.1"
7+
COURSIER="$HERE/.coursier"
8+
SCALAFMT="$HERE/.scalafmt-$VERSION"
9+
10+
if [ ! -f $COURSIER ]; then
11+
curl -L -o $COURSIER https://git.io/vgvpD
12+
chmod +x $COURSIER
13+
fi
14+
15+
if [ ! -f $SCALAFMT ]; then
16+
$COURSIER bootstrap com.geirsson:scalafmt-cli_2.11:$VERSION --main org.scalafmt.cli.Cli -o $SCALAFMT
17+
chmod +x $SCALAFMT
18+
fi
19+
20+
$SCALAFMT "$@"

build.sbt

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ val travisScalaVersion = sys.env.get("TRAVIS_SCALA_VERSION").flatMap(Version.par
254254
val releaseVersion = sys.env.get("TRAVIS_TAG").flatMap(Version.parse)
255255
val isScalaJs = sys.env.get("SCALAJS_VERSION").nonEmpty
256256
val isScalafix = sys.env.get("TEST_SCALAFIX").nonEmpty
257+
val isScalafmt = sys.env.get("TEST_SCALAFMT").nonEmpty
257258
val isBinaryCompat = sys.env.get("TEST_BINARY_COMPAT").nonEmpty
258259
val isRelease = releaseVersion.nonEmpty
259260

@@ -292,56 +293,69 @@ inThisBuild(Seq(
292293

293294
state
294295
},
296+
commands += Command.command("scalafmt-test") { state =>
297+
Seq("admin/scalafmt.sh", "--test") ! state.globalLogging.full
298+
state
299+
},
300+
commands += Command.command("scalafmt") { state =>
301+
Seq("admin/scalafmt.sh") ! state.globalLogging.full
302+
state
303+
},
295304
commands += Command.command("ci") { state =>
296-
val platformSuffix = if (isScalaJs) "JS" else ""
297-
298-
val compatProject = "compat" + travisScalaVersion.get.binary + platformSuffix
299-
val binaryCompatProject = "binary-compat"
300-
301-
val testProjectPrefix =
302-
if (isScalafix) {
303-
"scalafix-tests"
304-
} else if (isBinaryCompat) {
305-
binaryCompatProject
305+
val toRun =
306+
if (isScalafmt) {
307+
Seq("scalafmt-test")
306308
} else {
307-
compatProject
308-
}
309+
val platformSuffix = if (isScalaJs) "JS" else ""
310+
311+
val compatProject = "compat" + travisScalaVersion.get.binary + platformSuffix
312+
val binaryCompatProject = "binary-compat"
313+
314+
val testProjectPrefix =
315+
if (isScalafix) {
316+
"scalafix-tests"
317+
} else if (isBinaryCompat) {
318+
binaryCompatProject
319+
} else {
320+
compatProject
321+
}
309322

310-
val projectPrefix =
311-
if (isScalafix) {
312-
"scalafix-rules"
313-
} else if (isBinaryCompat) {
314-
binaryCompatProject
315-
} else {
316-
compatProject
317-
}
323+
val projectPrefix =
324+
if (isScalafix) {
325+
"scalafix-rules"
326+
} else if (isBinaryCompat) {
327+
binaryCompatProject
328+
} else {
329+
compatProject
330+
}
318331

319-
val setPublishVersion = releaseVersion.map("set every version := " + _).toList
332+
val setPublishVersion =
333+
releaseVersion.map("set every version := " + _).toList
334+
335+
val publishTask =
336+
if (releaseVersion.nonEmpty) {
337+
List(
338+
preRelease,
339+
s"$projectPrefix/publish-signed"
340+
)
341+
} else {
342+
Nil
343+
}
320344

321-
val publishTask =
322-
if (releaseVersion.nonEmpty) {
323-
List(
324-
preRelease,
325-
s"$projectPrefix/publish-signed"
326-
)
327-
} else {
328-
Nil
345+
Seq(
346+
setPublishVersion,
347+
List(s"$projectPrefix/clean"),
348+
List(s"$testProjectPrefix/test"),
349+
List(s"$projectPrefix/publishLocal"),
350+
publishTask
351+
).flatten
329352
}
330353

331-
val toRun = Seq(
332-
setPublishVersion,
333-
List(s"$projectPrefix/clean"),
334-
List(s"$testProjectPrefix/test"),
335-
List(s"$projectPrefix/publishLocal"),
336-
publishTask
337-
).flatten
338-
339354
println("---------")
340355
println("Running CI: ")
341356
toRun.foreach(println)
342357
println("---------")
343358

344-
345359
toRun ::: state
346360
}
347361
))

0 commit comments

Comments
 (0)