Skip to content

Commit

Permalink
Support markdown report in Gradle plugin (#4995)
Browse files Browse the repository at this point in the history
* Support markdown report in Gradle plugin

* Add markdown description to website docs

* Improve markdown description for website docs
  • Loading branch information
VitalyVPinchuk committed Jun 27, 2022
1 parent 4441bc4 commit 3b7cae1
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 5 deletions.
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
}
}

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
7 changes: 5 additions & 2 deletions website/docs/gettingstarted/gradle.mdx
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions website/docs/intro.mdx
Expand Up @@ -68,6 +68,7 @@ tasks.withType<Detekt>().configureEach {
html.required.set(true)
txt.required.set(true)
sarif.required.set(true)
md.required.set(true)
}
}
```
Expand All @@ -80,6 +81,7 @@ tasks.withType(Detekt).configureEach {
html.required.set(true)
txt.required.set(true)
sarif.required.set(true)
md.required.set(true)
}
}
```
Expand Down
1 change: 1 addition & 0 deletions website/docs/introduction/configurations.md
Expand Up @@ -126,6 +126,7 @@ output-reports:
# - 'TxtOutputReport'
# - 'XmlOutputReport'
# - 'SarifOutputReport'
# - 'MdOutputReport'
```


Expand Down
7 changes: 6 additions & 1 deletion website/docs/introduction/reporting.md
Expand Up @@ -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
Expand Down

0 comments on commit 3b7cae1

Please sign in to comment.