All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.detekt.report.xml.XmlOutputReport.kt Maven / Gradle / Ivy

There is a newer version: 1.23.7
Show newest version
package io.github.detekt.report.xml

import io.github.detekt.psi.toUnifiedString
import io.gitlab.arturbosch.detekt.api.Detektion
import io.gitlab.arturbosch.detekt.api.Finding
import io.gitlab.arturbosch.detekt.api.OutputReport
import java.util.Locale

/**
 * Contains rule violations in an XML format. The report follows the structure of a Checkstyle report.
 * See: https://detekt.github.io/detekt/configurations.html#output-reports
 */
class XmlOutputReport : OutputReport() {

    override val ending = "xml"

    override val name = "Checkstyle XML report"

    private val Finding.severityLabel: String
        get() = severity.name.toLowerCase(Locale.US)

    override fun render(detektion: Detektion): String {
        val smells = detektion.findings.flatMap { it.value }

        val lines = ArrayList()
        lines += ""
        lines += ""

        smells.groupBy { it.location.filePath.relativePath ?: it.location.filePath.absolutePath }
            .forEach { (filePath, findings) ->
                lines += ""
                findings.forEach {
                    lines += arrayOf(
                        "\t"
                    ).joinToString(separator = " ")
                }
                lines += ""
            }

        lines += ""
        return lines.joinToString(separator = "\n")
    }

    private fun Any.toXmlString() = XmlEscape.escapeXml(toString().trim())
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy