Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support markdown report in Gradle plugin #4995

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -76,6 +76,7 @@ tasks.withType<Detekt>().configureEach {
xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins
txt.required.set(true) // similar to the console output, contains issue signature to manually edit baseline files
sarif.required.set(true) // standardized SARIF format (https://sarifweb.azurewebsites.net/) to support integrations with Github Code Scanning
md.required.set(true) // simple Markdown format
VitalyVPinchuk marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Expand Up @@ -36,6 +36,7 @@ allprojects {
html.required.set(true)
txt.required.set(true)
sarif.required.set(true)
md.required.set(true)
}
}
tasks.withType<DetektCreateBaselineTask>().configureEach {
Expand Down Expand Up @@ -70,6 +71,7 @@ val detektFormat by tasks.registering(Detekt::class) {
xml.required.set(false)
html.required.set(false)
txt.required.set(false)
md.required.set(false)
}
}

Expand All @@ -88,6 +90,7 @@ val detektAll by tasks.registering(Detekt::class) {
xml.required.set(false)
html.required.set(false)
txt.required.set(false)
md.required.set(false)
}
}

Expand Down
1 change: 1 addition & 0 deletions code-coverage-report/build.gradle.kts
Expand Up @@ -26,6 +26,7 @@ dependencies {
jacocoAggregation(projects.detektReportSarif)
jacocoAggregation(projects.detektReportTxt)
jacocoAggregation(projects.detektReportXml)
jacocoAggregation(projects.detektReportMd)
jacocoAggregation(projects.detektRules)
jacocoAggregation(projects.detektRulesComplexity)
jacocoAggregation(projects.detektRulesCoroutines)
Expand Down
Expand Up @@ -79,7 +79,7 @@ class CliArgs {
names = ["--report", "-r"],
description = "Generates a report for given 'report-id' and stores it on given 'path'. " +
"Entry should consist of: [report-id:path]. " +
"Available 'report-id' values: 'txt', 'xml', 'html', 'sarif'. " +
"Available 'report-id' values: 'txt', 'xml', 'html', 'md', 'sarif'. " +
"These can also be used in combination with each other " +
"e.g. '-r txt:reports/detekt.txt -r xml:reports/detekt.xml'"
)
Expand Down
Expand Up @@ -321,6 +321,9 @@ class DetektTaskDslSpec {
| sarif {
| enabled = false
| }
| md {
| enabled = false
| }
| }
|}
"""
Expand Down
Expand Up @@ -189,6 +189,11 @@ open class Detekt @Inject constructor(
@Optional
get() = getTargetFileProvider(reports.sarif)

val mdReportFile: Provider<RegularFile>
@OutputFile
@Optional
get() = getTargetFileProvider(reports.md)

internal val customReportFiles: ConfigurableFileCollection
@OutputFiles
@Optional
Expand Down Expand Up @@ -217,6 +222,7 @@ open class Detekt @Inject constructor(
DefaultReportArgument(DetektReportType.HTML, htmlReportFile.orNull),
DefaultReportArgument(DetektReportType.TXT, txtReportFile.orNull),
DefaultReportArgument(DetektReportType.SARIF, sarifReportFile.orNull),
DefaultReportArgument(DetektReportType.MD, mdReportFile.orNull),
DebugArgument(debugProp.getOrElse(false)),
ParallelArgument(parallelProp.getOrElse(false)),
BuildUponDefaultConfigArgument(buildUponDefaultConfigProp.getOrElse(false)),
Expand Down
Expand Up @@ -5,7 +5,8 @@ enum class DetektReportType(val reportId: String, val extension: String) {
XML("xml", "xml"),
HTML("html", "html"),
TXT("txt", "txt"),
SARIF("sarif", "sarif");
SARIF("sarif", "sarif"),
MD("md", "md");

companion object {
fun isWellKnownReportId(reportId: String) = reportId in values().map(DetektReportType::reportId)
Expand Down
@@ -1,6 +1,7 @@
package io.gitlab.arturbosch.detekt.extensions

import io.gitlab.arturbosch.detekt.extensions.DetektReportType.HTML
import io.gitlab.arturbosch.detekt.extensions.DetektReportType.MD
import io.gitlab.arturbosch.detekt.extensions.DetektReportType.SARIF
import io.gitlab.arturbosch.detekt.extensions.DetektReportType.TXT
import io.gitlab.arturbosch.detekt.extensions.DetektReportType.XML
Expand All @@ -19,6 +20,8 @@ open class DetektReports @Inject constructor(val objects: ObjectFactory) {

val sarif: DetektReport = objects.newInstance(DetektReport::class.java, SARIF)

val md: DetektReport = objects.newInstance(DetektReport::class.java, MD)

val custom = mutableListOf<CustomDetektReport>()

fun xml(action: Action<in DetektReport>): Unit = action.execute(xml)
Expand All @@ -29,6 +32,8 @@ open class DetektReports @Inject constructor(val objects: ObjectFactory) {

fun sarif(action: Action<in DetektReport>): Unit = action.execute(sarif)

fun md(action: Action<in DetektReport>): Unit = action.execute(md)

fun custom(action: Action<in CustomDetektReport>): Unit = action.execute(createAndAddCustomReport())

private fun createAndAddCustomReport() =
Expand Down
Expand Up @@ -145,6 +145,7 @@ internal fun Project.setReportOutputConventions(reports: DetektReports, extensio
setReportOutputConvention(extension, reports.html, name, "html")
setReportOutputConvention(extension, reports.txt, name, "txt")
setReportOutputConvention(extension, reports.sarif, name, "sarif")
setReportOutputConvention(extension, reports.md, name, "md")
}

private fun Project.setReportOutputConvention(
Expand Down