diff --git a/README.md b/README.md index 046ada92c..0178caaf5 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ tasks.withType().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 } } diff --git a/build.gradle.kts b/build.gradle.kts index 24858abb4..15a04143a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,6 +36,7 @@ allprojects { html.required.set(true) txt.required.set(true) sarif.required.set(true) + md.required.set(true) } } tasks.withType().configureEach { @@ -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) } } @@ -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) } } diff --git a/code-coverage-report/build.gradle.kts b/code-coverage-report/build.gradle.kts index 3b3ea8bb6..74bfd6018 100644 --- a/code-coverage-report/build.gradle.kts +++ b/code-coverage-report/build.gradle.kts @@ -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) diff --git a/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgs.kt b/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgs.kt index 4d2714a5d..b223993bf 100644 --- a/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgs.kt +++ b/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgs.kt @@ -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'" ) diff --git a/detekt-gradle-plugin/src/functionalTest/kotlin/io/gitlab/arturbosch/detekt/DetektTaskDslSpec.kt b/detekt-gradle-plugin/src/functionalTest/kotlin/io/gitlab/arturbosch/detekt/DetektTaskDslSpec.kt index 33009439d..d0b43e87d 100644 --- a/detekt-gradle-plugin/src/functionalTest/kotlin/io/gitlab/arturbosch/detekt/DetektTaskDslSpec.kt +++ b/detekt-gradle-plugin/src/functionalTest/kotlin/io/gitlab/arturbosch/detekt/DetektTaskDslSpec.kt @@ -321,6 +321,9 @@ class DetektTaskDslSpec { | sarif { | enabled = false | } + | md { + | enabled = false + | } | } |} """ diff --git a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/Detekt.kt b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/Detekt.kt index 2af5d07ae..8f0c8b977 100644 --- a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/Detekt.kt +++ b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/Detekt.kt @@ -189,6 +189,11 @@ open class Detekt @Inject constructor( @Optional get() = getTargetFileProvider(reports.sarif) + val mdReportFile: Provider + @OutputFile + @Optional + get() = getTargetFileProvider(reports.md) + internal val customReportFiles: ConfigurableFileCollection @OutputFiles @Optional @@ -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)), diff --git a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektReportType.kt b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektReportType.kt index 124e72e20..0afbf1c25 100644 --- a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektReportType.kt +++ b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektReportType.kt @@ -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) diff --git a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektReports.kt b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektReports.kt index dcbf3e113..9a084c1af 100644 --- a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektReports.kt +++ b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektReports.kt @@ -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 @@ -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() fun xml(action: Action): Unit = action.execute(xml) @@ -29,6 +32,8 @@ open class DetektReports @Inject constructor(val objects: ObjectFactory) { fun sarif(action: Action): Unit = action.execute(sarif) + fun md(action: Action): Unit = action.execute(md) + fun custom(action: Action): Unit = action.execute(createAndAddCustomReport()) private fun createAndAddCustomReport() = diff --git a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/internal/DetektMultiplatform.kt b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/internal/DetektMultiplatform.kt index 4e124b1a2..06319abf0 100644 --- a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/internal/DetektMultiplatform.kt +++ b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/internal/DetektMultiplatform.kt @@ -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( diff --git a/website/docs/gettingstarted/gradle.mdx b/website/docs/gettingstarted/gradle.mdx index 535b29ed9..17425f09d 100644 --- a/website/docs/gettingstarted/gradle.mdx +++ b/website/docs/gettingstarted/gradle.mdx @@ -21,7 +21,7 @@ The detekt Gradle plugin will generate multiple tasks: - By default, the standard rule set without any ignore list is executed on sources files located in `src/main/java`, `src/test/java`, `src/main/kotlin` and `src/test/kotlin`. - Reports are automatically generated in xml, - html, txt, and sarif format and can be found in `build/reports/detekt/detekt.[xml|html|txt|sarif]` respectively. + html, txt, md, and sarif format and can be found in `build/reports/detekt/detekt.[xml|html|txt|md|sarif]` respectively. - Please note that the `detekt` task is automatically run when executing `gradle check`. - You may specify Gradle task CLI option for auto correction, such as `gradle detekt --auto-correct`. - `detektGenerateConfig` - Generates a default detekt configuration file into your project directory. @@ -48,7 +48,7 @@ the name of the build variant in their name, unless otherwise configured, such a `detekt-productionDebug.xml`. If both, a `detekt-main.xml` and a `detekt.xml` baseline file exists in place, the more specific one - `detekt-main.xml` - -takes precendence when the `detektMain` task is executed, likewise for Android variant-specific baseline files. +takes precedence when the `detektMain` task is executed, likewise for Android variant-specific baseline files. _NOTE:_ When analyzing Android projects that make use of specific code generators, such as Data Binding, Kotlin synthetic view accessors or else, you might see warnings output while Detekt runs. This is due to the inability to gather the @@ -318,6 +318,9 @@ tasks.named("detekt").configure { // Enable/Disable SARIF report (default: false) sarif.required.set(true) sarif.outputLocation.set(file("build/reports/detekt.sarif")) + // Enable/Disable MD report (default: false) + md.required.set(true) + md.outputLocation.set(file("build/reports/detekt.md")) custom { // The simple class name of your custom report. reportId = "CustomJsonReport" diff --git a/website/docs/intro.mdx b/website/docs/intro.mdx index 1bddd10ff..5628b9ba8 100644 --- a/website/docs/intro.mdx +++ b/website/docs/intro.mdx @@ -68,6 +68,7 @@ tasks.withType().configureEach { html.required.set(true) txt.required.set(true) sarif.required.set(true) + md.required.set(true) } } ``` @@ -80,6 +81,7 @@ tasks.withType(Detekt).configureEach { html.required.set(true) txt.required.set(true) sarif.required.set(true) + md.required.set(true) } } ``` diff --git a/website/docs/introduction/configurations.md b/website/docs/introduction/configurations.md index 40fe937d4..26f7b2bde 100644 --- a/website/docs/introduction/configurations.md +++ b/website/docs/introduction/configurations.md @@ -126,6 +126,7 @@ output-reports: # - 'TxtOutputReport' # - 'XmlOutputReport' # - 'SarifOutputReport' + # - 'MdOutputReport' ``` diff --git a/website/docs/introduction/reporting.md b/website/docs/introduction/reporting.md index b73b7670e..eb7be2611 100644 --- a/website/docs/introduction/reporting.md +++ b/website/docs/introduction/reporting.md @@ -37,7 +37,12 @@ XML is a machine-readable format that can be integrated with CI tools. It is com [SARIF](https://sarifweb.azurewebsites.net/) is a standard format for the output of static analysis tools. It is a JSON format with a defined [schema](https://docs.oasis-open.org/sarif/sarif/v2.0/csprd02/schemas/). It is currently supported -by Github Code Scanning and we expect more consuming tools will be adopt this format in the future. +by GitHub Code Scanning, and we expect more consuming tools will adopt this format in the future. + +### MD +Markdown is a lightweight markup language for creating formatted text using a plain-text editor. +The output structure looks similar to HTML format. +About [markdown](https://github.github.com/gfm/#what-is-markdown-) on GitHub. ## Severity For machine-readable format, it is possible to configure the severity of each finding to fit