-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathScalafmtSbtReporter.scala
39 lines (30 loc) · 1.15 KB
/
ScalafmtSbtReporter.scala
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
package org.scalafmt.sbt
import java.io.PrintWriter
import java.io.OutputStreamWriter
import java.nio.file.Path
import org.scalafmt.interfaces.ScalafmtReporter
import sbt.internal.util.MessageOnlyException
import sbt.util.Logger
import scala.util.control.NoStackTrace
class ScalafmtSbtReporter(log: Logger, out: OutputStreamWriter)
extends ScalafmtReporter {
override def error(file: Path, message: String): Unit = {
throw new MessageOnlyException(s"$message: $file")
}
override def error(file: Path, e: Throwable): Unit = {
if (e.getMessage != null) {
error(file, e.getMessage)
} else {
throw new FailedToFormat(file.toString, e)
}
}
override def excluded(file: Path): Unit =
log.debug(s"file excluded: $file")
override def parsedConfig(config: Path, scalafmtVersion: String): Unit =
log.debug(s"parsed config (v$scalafmtVersion): $config")
override def downloadWriter(): PrintWriter = new PrintWriter(out)
override def downloadOutputStreamWriter(): OutputStreamWriter = out
private class FailedToFormat(filename: String, cause: Throwable)
extends Exception(filename, cause)
with NoStackTrace
}