diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-12-12 16:56:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 16:56:02 -0800 |
commit | 9ba4cb69331386dfde9bac69dc2d5b22401face3 (patch) | |
tree | 120349e8015ae5717d36bd44209cde6ff9543518 /scalalib/src/scalafmt/ScalafmtModule.scala | |
parent | ea7fceb6e56f53bde3517586dfc57e10a605a524 (diff) | |
download | mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.tar.gz mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.tar.bz2 mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.zip |
collapse boilerplate folder structure within src/ folders (#505)
* collapse boilerplate folder structure within src/ folders
* .
Diffstat (limited to 'scalalib/src/scalafmt/ScalafmtModule.scala')
-rw-r--r-- | scalalib/src/scalafmt/ScalafmtModule.scala | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/scalalib/src/scalafmt/ScalafmtModule.scala b/scalalib/src/scalafmt/ScalafmtModule.scala new file mode 100644 index 00000000..6a81d975 --- /dev/null +++ b/scalalib/src/scalafmt/ScalafmtModule.scala @@ -0,0 +1,57 @@ +package mill.scalalib.scalafmt + +import mill._ +import mill.define._ +import mill.scalalib._ + +trait ScalafmtModule extends JavaModule { + + def reformat(): Command[Unit] = T.command { + ScalafmtWorkerModule + .worker() + .reformat( + filesToFormat(sources()), + scalafmtConfig().head, + scalafmtDeps().map(_.path) + ) + } + + def scalafmtVersion: T[String] = "1.5.1" + + def scalafmtConfig: Sources = T.sources(os.pwd / ".scalafmt.conf") + + def scalafmtDeps: T[Agg[PathRef]] = T { + Lib.resolveDependencies( + zincWorker.repositories, + Lib.depToDependency(_, "2.12.4"), + Seq(ivy"com.geirsson::scalafmt-cli:${scalafmtVersion()}") + ) + } + + protected def filesToFormat(sources: Seq[PathRef]) = { + for { + pathRef <- sources if os.exists(pathRef.path) + file <- os.walk(pathRef.path) if os.isFile(file) && file.ext == "scala" + } yield PathRef(file) + } + +} + +object ScalafmtModule extends ExternalModule with ScalafmtModule { + + def reformatAll(sources: mill.main.Tasks[Seq[PathRef]]): Command[Unit] = + T.command { + val files = Task.sequence(sources.value)().flatMap(filesToFormat) + ScalafmtWorkerModule + .worker() + .reformat( + files, + scalafmtConfig().head, + scalafmtDeps().map(_.path) + ) + } + + implicit def millScoptTargetReads[T] = new mill.main.Tasks.Scopt[T]() + + lazy val millDiscover = Discover[this.type] +} |