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

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

The newest version!
package io.github.detekt.report.xml

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
import kotlin.io.path.invariantSeparatorsPathString

/**
 * Contains rule violations in an XML format. The report follows the structure of a Checkstyle report.
 * See: https://detekt.dev/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.lowercase(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