-
Notifications
You must be signed in to change notification settings - Fork 43
/
ScalafixLogger.scala
39 lines (36 loc) · 1.31 KB
/
ScalafixLogger.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 scalafix.internal.sbt
import scalafix.interfaces.ScalafixDiagnostic
import scalafix.interfaces.ScalafixLintID
import scalafix.interfaces.ScalafixMainCallback
import scalafix.interfaces.ScalafixSeverity
import sbt.Logger
class ScalafixLogger(logger: Logger) extends ScalafixMainCallback {
def fullStringID(lintID: ScalafixLintID): String =
if (lintID.categoryID().isEmpty) lintID.ruleName()
else if (lintID.ruleName().isEmpty) lintID.categoryID()
else s"${lintID.ruleName()}.${lintID.categoryID()}"
override def reportDiagnostic(diagnostic: ScalafixDiagnostic): Unit = {
def formatMessage: String = {
val prefix =
if (diagnostic.lintID().isPresent) {
val id = fullStringID(diagnostic.lintID().get)
s"[$id] "
} else {
""
}
val message = prefix + diagnostic.message()
if (diagnostic.position().isPresent) {
val severity =
diagnostic.severity().toString.toLowerCase()
diagnostic.position().get().formatMessage(severity, message)
} else {
message
}
}
diagnostic.severity() match {
case ScalafixSeverity.INFO => logger.info(formatMessage)
case ScalafixSeverity.WARNING => logger.warn(formatMessage)
case ScalafixSeverity.ERROR => logger.error(formatMessage)
}
}
}