-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new ConsoleReport format (#4027)
* Add a new ConsoleReport format * Consolidate duplicate console report logic to an abstract class
- Loading branch information
1 parent
ad254eb
commit 72d7e4f
Showing
11 changed files
with
119 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../main/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/AbstractFindingsReport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.gitlab.arturbosch.detekt.core.reporting.console | ||
|
||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.api.ConsoleReport | ||
import io.gitlab.arturbosch.detekt.api.Detektion | ||
import io.gitlab.arturbosch.detekt.api.Finding | ||
import io.gitlab.arturbosch.detekt.api.RuleSetId | ||
import io.gitlab.arturbosch.detekt.api.SingleAssign | ||
import io.gitlab.arturbosch.detekt.core.reporting.filterEmptyIssues | ||
|
||
abstract class AbstractFindingsReport : ConsoleReport() { | ||
|
||
private var config: Config by SingleAssign() | ||
|
||
override val priority: Int = 40 | ||
|
||
override fun init(config: Config) { | ||
this.config = config | ||
} | ||
|
||
override fun render(detektion: Detektion): String? { | ||
val findings = detektion.filterEmptyIssues(config) | ||
if (findings.isEmpty()) { | ||
return null | ||
} | ||
return render(findings) | ||
} | ||
|
||
abstract fun render(findings: Map<RuleSetId, List<Finding>>): String | ||
} |
24 changes: 4 additions & 20 deletions
24
...main/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/FileBasedFindingsReport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 4 additions & 22 deletions
26
...core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/FindingsReport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,14 @@ | ||
package io.gitlab.arturbosch.detekt.core.reporting.console | ||
|
||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.api.ConsoleReport | ||
import io.gitlab.arturbosch.detekt.api.Detektion | ||
import io.gitlab.arturbosch.detekt.api.SingleAssign | ||
import io.gitlab.arturbosch.detekt.core.reporting.filterEmptyIssues | ||
import io.gitlab.arturbosch.detekt.api.Finding | ||
import io.gitlab.arturbosch.detekt.api.RuleSetId | ||
import io.gitlab.arturbosch.detekt.core.reporting.printFindings | ||
|
||
/** | ||
* Contains all rule violations in a list format grouped by ruleset. | ||
* See: https://detekt.github.io/detekt/configurations.html#console-reports | ||
*/ | ||
class FindingsReport : ConsoleReport() { | ||
class FindingsReport : AbstractFindingsReport() { | ||
|
||
private var config: Config by SingleAssign() | ||
|
||
override val priority: Int = 40 | ||
|
||
override fun init(config: Config) { | ||
this.config = config | ||
} | ||
|
||
override fun render(detektion: Detektion): String? { | ||
val findings = detektion.filterEmptyIssues(config) | ||
if (findings.isEmpty()) { | ||
return null | ||
} | ||
|
||
return printFindings(findings) | ||
} | ||
override fun render(findings: Map<RuleSetId, List<Finding>>): String = printFindings(findings) | ||
} |
20 changes: 20 additions & 0 deletions
20
.../src/main/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/LiteFindingsReport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.gitlab.arturbosch.detekt.core.reporting.console | ||
|
||
import io.gitlab.arturbosch.detekt.api.Finding | ||
import io.gitlab.arturbosch.detekt.api.RuleSetId | ||
|
||
/** | ||
* A lightweight versions of the console report, where each line contains location, messages and issue id only. | ||
* See: https://detekt.github.io/detekt/configurations.html#console-reports | ||
*/ | ||
class LiteFindingsReport : AbstractFindingsReport() { | ||
|
||
override fun render(findings: Map<RuleSetId, List<Finding>>): String { | ||
return buildString { | ||
findings.values.flatten().forEach { finding -> | ||
append("${finding.location.compact()}: ${finding.messageOrDescription()} [${finding.issue.id}]") | ||
appendLine() | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...t-core/src/main/resources/META-INF/services/io.gitlab.arturbosch.detekt.api.ConsoleReport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
io.gitlab.arturbosch.detekt.core.reporting.console.ComplexityReport | ||
io.gitlab.arturbosch.detekt.core.reporting.console.FindingsReport | ||
io.gitlab.arturbosch.detekt.core.reporting.console.FileBasedFindingsReport | ||
io.gitlab.arturbosch.detekt.core.reporting.console.LiteFindingsReport | ||
io.gitlab.arturbosch.detekt.core.reporting.console.NotificationReport | ||
io.gitlab.arturbosch.detekt.core.reporting.console.ProjectStatisticsReport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../test/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/LiteFindingsReportSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.gitlab.arturbosch.detekt.core.reporting.console | ||
|
||
import io.github.detekt.test.utils.readResourceContent | ||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.api.Finding | ||
import io.gitlab.arturbosch.detekt.core.reporting.AutoCorrectableIssueAssert | ||
import io.gitlab.arturbosch.detekt.test.TestDetektion | ||
import io.gitlab.arturbosch.detekt.test.createFinding | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.style.specification.describe | ||
|
||
class LiteFindingsReportSpec : Spek({ | ||
|
||
val subject by memoized { createFindingsReport() } | ||
|
||
describe("findings report") { | ||
it("reports non-empty findings") { | ||
assertThat( | ||
subject | ||
.render( | ||
TestDetektion( | ||
createFinding("SpacingBetweenPackageAndImports"), | ||
createFinding("UnnecessarySafeCall") | ||
) | ||
) | ||
).isEqualTo(readResourceContent("/reporting/lite-findings-report.txt")) | ||
} | ||
|
||
it("reports no findings") { | ||
val detektion = TestDetektion() | ||
assertThat(subject.render(detektion)).isNull() | ||
} | ||
|
||
it("reports no findings with rule set containing no smells") { | ||
val detektion = object : TestDetektion() { | ||
override val findings: Map<String, List<Finding>> = mapOf( | ||
"Ruleset" to emptyList() | ||
) | ||
} | ||
assertThat(subject.render(detektion)).isNull() | ||
} | ||
|
||
it("should not add auto corrected issues to report") { | ||
val report = FindingsReport() | ||
AutoCorrectableIssueAssert.isReportNull(report) | ||
} | ||
} | ||
}) | ||
|
||
private fun createFindingsReport() = LiteFindingsReport().apply { | ||
init(Config.empty) | ||
} |
2 changes: 2 additions & 0 deletions
2
detekt-core/src/test/resources/reporting/lite-findings-report.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
TestFile.kt:1:1: TestMessage [SpacingBetweenPackageAndImports] | ||
TestFile.kt:1:1: TestMessage [UnnecessarySafeCall] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters