com.pinterest.ktlint.reporter.baseline.BaselineReporter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktlint-reporter-baseline Show documentation
Show all versions of ktlint-reporter-baseline Show documentation
An anti-bikeshedding Kotlin linter with built-in formatter.
package com.pinterest.ktlint.reporter.baseline
import com.pinterest.ktlint.core.LintError
import com.pinterest.ktlint.core.Reporter
import java.io.File
import java.io.PrintStream
import java.nio.file.Paths
import java.util.ArrayList
import java.util.concurrent.ConcurrentHashMap
class BaselineReporter(val out: PrintStream) : Reporter {
private val acc = ConcurrentHashMap>()
override fun onLintError(file: String, err: LintError, corrected: Boolean) {
if (!corrected) {
acc.getOrPut(file) { ArrayList() }.add(err)
}
}
override fun afterAll() {
out.println("""""")
out.println("""""")
for ((file, errList) in acc.entries.sortedBy { it.key }) {
val fileName = try {
val rootPath = Paths.get("").toAbsolutePath()
val filePath = Paths.get(file)
rootPath.relativize(filePath).toString().replace(File.separatorChar, '/')
} catch (e: IllegalArgumentException) {
file
}
out.println(""" """)
for ((line, col, ruleId, _) in errList) {
out.println(
""" """
)
}
out.println(""" """)
}
out.println(""" """)
}
private fun String.escapeXMLAttrValue() =
this.replace("&", "&").replace("\"", """).replace("'", "'")
.replace("<", "<").replace(">", ">")
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy