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
Add a new ConsoleReport format #4027
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a08ef8d
Add a new ConsoleReport format
chao2zhang bd0d4f2
Consolidate duplicate console report logic to an abstract class
chao2zhang ec77608
Update referenced names
chao2zhang e4968fe
Merge remote-tracking branch 'detekt/main' into consolereport
chao2zhang c565616
Address Detekt violations
chao2zhang File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
.../main/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/ReadableFindingsReport.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,35 @@ | ||
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 | ||
|
||
/** | ||
* Contains a clear read of the console report, where each line contains location, messages and issue id. | ||
* See: https://detekt.github.io/detekt/configurations.html#console-reports | ||
*/ | ||
class ReadableFindingsReport : 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 issues = detektion.filterEmptyIssues(config) | ||
if (issues.isEmpty()) { | ||
return null | ||
} | ||
return buildString { | ||
issues.values.flatten().forEach { finding -> | ||
append("${finding.location.compact()}: ${finding.messageOrDescription()} [${finding.issue.id}]") | ||
chao2zhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.ReadableFindingsReport | ||
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
...t/kotlin/io/gitlab/arturbosch/detekt/core/reporting/console/ReadableFindingsReportSpec.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 ReadableFindingsReportSpec : 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/readable-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( | ||
Pair("Ruleset", emptyList()) | ||
) | ||
} | ||
assertThat(subject.render(detektion)).isNull() | ||
} | ||
|
||
it("should not add auto corrected issues to report") { | ||
val report = FindingsReport() | ||
AutoCorrectableIssueAssert.isReportNull(report) | ||
} | ||
} | ||
}) | ||
|
||
private fun createFindingsReport() = ReadableFindingsReport().apply { | ||
init(Config.empty) | ||
} |
2 changes: 2 additions & 0 deletions
2
detekt-core/src/test/resources/reporting/readable-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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we refactor
FindingsReport
and this class to a single hierarchy? Apparently the difference is just the(Map<String, List<Finding>>) -> String
function that they're invoking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't call this ReadableFindingsReport. Is the other FindingsReport not readable? I would prefer to call it ConciseFindingsReport.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the name to
LiteFindingsReport
as suggested above.