-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
maxColumn = 100 | ||
project.git = true | ||
project.excludeFilters = [ /sbt-test/, /input_sources/, /contraband-scala/ ] | ||
|
||
# http://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style. | ||
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala | ||
docstrings = JavaDoc | ||
|
||
# This also seems more idiomatic to include whitespace in import x.{ yyy } | ||
spaces.inImportCurlyBraces = true | ||
|
||
# This works around sequence wildcard (`_*`) turning into `_ *` | ||
spaces.beforeSeqWildcard = true | ||
|
||
# Vertical alignment only => for pattern matching | ||
align.tokens.add = [ | ||
{ code = "=>", owner = "Case" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import org.scalafmt.bootstrap.ScalafmtBootstrap | ||
import org.scalafmt.sbt.ScalafmtPlugin | ||
import sbt._ | ||
import sbt.Keys._ | ||
import sbt.inc.Analysis | ||
|
||
// Taken from https://github.com/akka/alpakka/blob/master/project/AutomateScalafmtPlugin.scala | ||
object AutomateScalafmtPlugin extends AutoPlugin { | ||
object autoImport { | ||
def automateScalafmtFor(configurations: Configuration*): Seq[Setting[_]] = | ||
configurations.flatMap { c => | ||
inConfig(c)( | ||
Seq( | ||
compileInputs.in(compile) := { | ||
scalafmtInc.value | ||
compileInputs.in(compile).value | ||
}, | ||
sourceDirectories.in(scalafmtInc) := Seq(scalaSource.value), | ||
scalafmtInc := { | ||
val cache = streams.value.cacheDirectory / "scalafmt" | ||
val include = includeFilter.in(scalafmtInc).value | ||
val exclude = excludeFilter.in(scalafmtInc).value | ||
val sources = | ||
sourceDirectories | ||
.in(scalafmtInc) | ||
.value | ||
.descendantsExcept(include, exclude) | ||
.get | ||
.toSet | ||
def format(handler: Set[File] => Unit, msg: String) = { | ||
def update(handler: Set[File] => Unit, msg: String)(in: ChangeReport[File], | ||
out: ChangeReport[File]) = { | ||
val label = Reference.display(thisProjectRef.value) | ||
val files = in.modified -- in.removed | ||
Analysis | ||
.counted("Scala source", "", "s", files.size) | ||
.foreach(count => streams.value.log.info(s"$msg $count in $label ...")) | ||
handler(files) | ||
files | ||
} | ||
FileFunction.cached(cache)(FilesInfo.hash, FilesInfo.exists)(update(handler, msg))( | ||
sources | ||
) | ||
} | ||
def formattingHandler(files: Set[File]) = | ||
if (files.nonEmpty) { | ||
val filesArg = files.map(_.getAbsolutePath).mkString(",") | ||
ScalafmtBootstrap.main(List("--quiet", "-i", "-f", filesArg)) | ||
} | ||
format(formattingHandler, "Formatting") | ||
format(_ => (), "Reformatted") // Recalculate the cache | ||
} | ||
) | ||
) | ||
} | ||
} | ||
|
||
private val scalafmtInc = taskKey[Unit]("Incrementally format modified sources") | ||
|
||
override def requires = ScalafmtPlugin | ||
|
||
override def trigger = allRequirements | ||
|
||
override def projectSettings = | ||
(includeFilter.in(scalafmtInc) := "*.scala") +: autoImport.automateScalafmtFor(Compile, Test) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.21") | ||
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.6.8") |