Skip to content

Commit

Permalink
Merge pull request #23 from mpollmeier/test-on-compile
Browse files Browse the repository at this point in the history
additional setting: scalafmtTestOnCompile
  • Loading branch information
pauldraper authored Jun 23, 2017
2 parents 0b9b18a + 7e4d521 commit b7d8ce2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ scalafmtOnCompile := true // current project
scalafmtOnCompile in Compile := true // current project, specific configuration
```

To run scalafmt::test automatically before compiling (or before loading, in the case of sbt).

```scala
scalafmtTestOnCompile in ThisBuild := true // all projects
scalafmtTestOnCompile := true // current project
scalafmtTestOnCompile in Compile := true // current project, specific configuration
```

By default, scalafmt fails the build for any style issues. If you'd prefer warnings instead:

```scala
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ object ScalafmtCorePlugin extends AutoPlugin {
val scalafmtConfig = TaskKey[File]("scalafmt-config", "Scalafmtter config file", BTask)
val scalafmtDialect = SettingKey[Dialect]("scalafmt-dialect", "Dialect of Scala sources", BSetting)
val scalafmtOnCompile = SettingKey[Boolean]("scalafmt-on-compile", "Format source when compiling", BTask)
val scalafmtTestOnCompile =
SettingKey[Boolean]("scalafmt-test-on-compile", "Check source format when compiling", BTask)
// A better way is to put things in a sbt-scalafmt-ivy plugin, but this stuff is currently in flux.
val scalafmtUseIvy = SettingKey[Boolean]("scalafmt-use-ivy", "Use sbt's Ivy resolution", CSetting)
val scalafmtVersion = SettingKey[String]("scalafmt-version", "Scalafmtter version", AMinusSetting)
Expand Down Expand Up @@ -183,7 +185,10 @@ object ScalafmtCorePlugin extends AutoPlugin {
val scalafmtSettings = scalafmtCoreSettings ++
Seq(
compileInputs in compile := Def.taskDyn {
val task = if (scalafmtOnCompile.value) scalafmt in resolvedScoped.value.scope else Def.task(())
val task =
if (scalafmtOnCompile.value) scalafmt in resolvedScoped.value.scope
else if (scalafmtTestOnCompile.value) test in (resolvedScoped.value.scope in scalafmt.key)
else Def.task(())
val previousInputs = (compileInputs in compile).value
task.map(_ => previousInputs)
}.value
Expand Down Expand Up @@ -216,6 +221,7 @@ object ScalafmtCorePlugin extends AutoPlugin {
.maximumSize(3),
scalafmtConfig := (baseDirectory in ThisBuild).value / ".scalafmt.conf",
scalafmtOnCompile := false,
scalafmtTestOnCompile := false,
scalafmtVersion := "0.6.8",
scalafmtFailTest := true
)
Expand Down

0 comments on commit b7d8ce2

Please sign in to comment.