-
-
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.
Create DetailedFindingsReport ConsoleReport format
- Loading branch information
Showing
7 changed files
with
111 additions
and
2 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
22 changes: 22 additions & 0 deletions
22
.../main/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/DetailedFindingsReport.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,22 @@ | ||
package io.gitlab.arturbosch.detekt.core.reporting.console | ||
|
||
import io.gitlab.arturbosch.detekt.api.Finding | ||
import io.gitlab.arturbosch.detekt.api.RuleSetId | ||
import io.gitlab.arturbosch.detekt.api.ThresholdedCodeSmell | ||
import io.gitlab.arturbosch.detekt.core.reporting.printFindings | ||
|
||
/** | ||
* Displays findings laid out similar to regular FindingsReport, but also | ||
* includes the description for the rule found for clarity. | ||
*/ | ||
class DetailedFindingsReport : AbstractFindingsReport() { | ||
|
||
override fun render(findings: Map<RuleSetId, List<Finding>>): String = printFindings(findings) { | ||
when (this) { | ||
is ThresholdedCodeSmell -> "$id - $metric - ${detailedReport()}" | ||
else -> "$id - ${detailedReport()}" | ||
} | ||
} | ||
|
||
private fun Finding.detailedReport() = "[${messageOrDescription()}] at ${location.compact()}" | ||
} |
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
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
74 changes: 74 additions & 0 deletions
74
...t/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/DetailedFindingsReportSpec.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,74 @@ | ||
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.core.reporting.decolorized | ||
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 DetailedFindingsReportSpec : Spek({ | ||
|
||
val subject by memoized { createFindingsReport() } | ||
|
||
describe("findings report") { | ||
|
||
context("reports the debt per rule set and the overall debt") { | ||
val expectedContent by memoized { | ||
readResourceContent("/reporting/detailed-findings-report.txt") | ||
} | ||
val detektion by memoized { | ||
object : TestDetektion() { | ||
override val findings: Map<String, List<Finding>> = mapOf( | ||
"Ruleset1" to listOf(createFinding(), createFinding()), | ||
"EmptyRuleset" to emptyList(), | ||
"Ruleset2" to listOf(createFinding()) | ||
) | ||
} | ||
} | ||
|
||
var output: String? = null | ||
|
||
beforeEachTest { | ||
output = subject.render(detektion)?.decolorized() | ||
} | ||
|
||
it("has the reference content") { | ||
assertThat(output).isEqualTo(expectedContent) | ||
} | ||
|
||
it("does contain the rule set id of rule sets with findings") { | ||
assertThat(output).contains("TestSmell") | ||
} | ||
} | ||
|
||
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 = DetailedFindingsReport() | ||
AutoCorrectableIssueAssert.isReportNull(report) | ||
} | ||
} | ||
}) | ||
|
||
private fun createFindingsReport(): DetailedFindingsReport { | ||
val report = DetailedFindingsReport() | ||
report.init(Config.empty) | ||
return report | ||
} |
7 changes: 7 additions & 0 deletions
7
detekt-core/src/test/resources/reporting/detailed-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,7 @@ | ||
Ruleset1 - 10min debt | ||
TestSmell - [TestMessage] at TestFile.kt:1:1 | ||
TestSmell - [TestMessage] at TestFile.kt:1:1 | ||
Ruleset2 - 5min debt | ||
TestSmell - [TestMessage] at TestFile.kt:1:1 | ||
|
||
Overall debt: 15min |
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