Skip to content

Commit 8f18368

Browse files
authored
Merge pull request scalacenter#1780 from tgodzik/add-hook
chore: Automatically add hook for validating formatting
2 parents 9e4671e + 9780c1b commit 8f18368

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

build.sbt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ ThisBuild / bloopExportJarClassifiers := Some(Set("sources"))
1313

1414
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"
1515

16+
// Add hook for scalafmt validation
17+
Global / onLoad ~= { old =>
18+
if (!scala.util.Properties.isWin) {
19+
import java.nio.file._
20+
val prePush = Paths.get(".git", "hooks", "pre-push")
21+
Files.createDirectories(prePush.getParent)
22+
Files.write(
23+
prePush,
24+
"""#!/bin/sh
25+
|set -eux
26+
|bin/scalafmt --diff --diff-branch main
27+
|git diff --exit-code
28+
|""".stripMargin.getBytes()
29+
)
30+
prePush.toFile.setExecutable(true)
31+
}
32+
old
33+
}
34+
1635
val scalafixSettings: Seq[Setting[_]] = Seq(
1736
scalacOptions ++= {
1837
if (scalaVersion.value.startsWith("2.11")) Seq("-Ywarn-unused-import")

0 commit comments

Comments
 (0)