blob: ea254e6d570caf7a8737dee24cb42590429c36d1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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
)
}
def scalafmtConfig: Sources = T.sources(os.pwd / ".scalafmt.conf")
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
)
}
implicit def millScoptTargetReads[T] = new mill.main.Tasks.Scopt[T]()
lazy val millDiscover = Discover[this.type]
}
|