Skip to content

Commit

Permalink
Creates detailed() Findings report format
Browse files Browse the repository at this point in the history
Moves the changes to the compact() method to a detailed() method and
reverts the changes to the compact() method.
  • Loading branch information
gfreivasc committed Jan 18, 2022
1 parent 0a9dd93 commit fcdc20e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions detekt-api/api/detekt-api.api
Expand Up @@ -31,6 +31,7 @@ public class io/gitlab/arturbosch/detekt/api/CodeSmell : io/gitlab/arturbosch/de
public synthetic fun <init> (Lio/gitlab/arturbosch/detekt/api/Issue;Lio/gitlab/arturbosch/detekt/api/Entity;Ljava/lang/String;Ljava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun compact ()Ljava/lang/String;
public fun compactWithSignature ()Ljava/lang/String;
public fun detailed ()Ljava/lang/String;
public fun getCharPosition ()Lio/gitlab/arturbosch/detekt/api/TextLocation;
public fun getEntity ()Lio/gitlab/arturbosch/detekt/api/Entity;
public fun getFile ()Ljava/lang/String;
Expand Down Expand Up @@ -282,6 +283,7 @@ public final class io/gitlab/arturbosch/detekt/api/FileProcessListener$DefaultIm
}

public abstract interface class io/gitlab/arturbosch/detekt/api/Finding : io/gitlab/arturbosch/detekt/api/Compactable, io/gitlab/arturbosch/detekt/api/HasEntity, io/gitlab/arturbosch/detekt/api/HasMetrics {
public abstract fun detailed ()Ljava/lang/String;
public abstract fun getId ()Ljava/lang/String;
public abstract fun getIssue ()Lio/gitlab/arturbosch/detekt/api/Issue;
public abstract fun getMessage ()Ljava/lang/String;
Expand Down Expand Up @@ -605,6 +607,7 @@ public class io/gitlab/arturbosch/detekt/api/ThresholdedCodeSmell : io/gitlab/ar
public fun <init> (Lio/gitlab/arturbosch/detekt/api/Issue;Lio/gitlab/arturbosch/detekt/api/Entity;Lio/gitlab/arturbosch/detekt/api/Metric;Ljava/lang/String;Ljava/util/List;)V
public synthetic fun <init> (Lio/gitlab/arturbosch/detekt/api/Issue;Lio/gitlab/arturbosch/detekt/api/Entity;Lio/gitlab/arturbosch/detekt/api/Metric;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun compact ()Ljava/lang/String;
public fun detailed ()Ljava/lang/String;
public final fun getMetric ()Lio/gitlab/arturbosch/detekt/api/Metric;
public final fun getThreshold ()I
public final fun getValue ()I
Expand Down
Expand Up @@ -24,7 +24,7 @@ open class CodeSmell(

override val id: String = issue.id

override fun compact(): String = "$id - ${messageWithLocation()}"
override fun compact(): String = "$id - ${entity.compact()}"

override fun compactWithSignature(): String = compact() + " - Signature=" + entity.signature

Expand All @@ -40,6 +40,8 @@ open class CodeSmell(

override fun messageOrDescription(): String = message.ifEmpty { issue.description }

override fun detailed(): String = "$id - ${messageWithLocation()}"

private fun messageWithLocation() = "[${messageOrDescription()}] at ${location.compact()}"
}

Expand Down Expand Up @@ -100,9 +102,11 @@ open class ThresholdedCodeSmell(
val threshold: Int
get() = metric.threshold

override fun compact(): String = "$id - $metric - ${messageWithLocation()}"
override fun compact(): String = "$id - $metric - ${entity.compact()}"

override fun messageOrDescription(): String = message.ifEmpty { issue.description }

override fun detailed(): String = "$id - $metric - ${messageWithLocation()}"

private fun messageWithLocation() = "[${messageOrDescription()}] at ${location.compact()}"
}
Expand Up @@ -19,6 +19,12 @@ interface Finding : Compactable, HasEntity, HasMetrics {
* Explanation why this finding was raised.
*/
fun messageOrDescription(): String

/**
* Findings description in a similar shaped to the compact description
* but also containing the underlying issue message.
*/
fun detailed(): String
}

/**
Expand Down
Expand Up @@ -30,7 +30,7 @@ internal fun printFindings(findings: Map<String, List<Finding>>): String {
append("$key - $debt debt\n")
issues.forEach {
append("\t")
append(it.compact().yellow())
append(it.detailed().yellow())
append("\n")
}
}
Expand Down
Expand Up @@ -20,7 +20,7 @@ class TxtOutputReportSpec : Spek({
it("renders one") {
val report = TxtOutputReport()
val detektion = TestDetektion(createFinding())
val renderedText = "TestSmell - [TestMessage] at TestFile.kt:1:1 - Signature=TestEntitySignature\n"
val renderedText = "TestSmell - [TestEntity] at TestFile.kt:1:1 - Signature=TestEntitySignature\n"
assertThat(report.render(detektion)).isEqualTo(renderedText)
}

Expand All @@ -32,9 +32,9 @@ class TxtOutputReportSpec : Spek({
createFinding(ruleName = "TestSmellC")
)
val renderedText = """
TestSmellA - [TestMessage] at TestFile.kt:1:1 - Signature=TestEntitySignature
TestSmellB - [TestMessage] at TestFile.kt:1:1 - Signature=TestEntitySignature
TestSmellC - [TestMessage] at TestFile.kt:1:1 - Signature=TestEntitySignature
TestSmellA - [TestEntity] at TestFile.kt:1:1 - Signature=TestEntitySignature
TestSmellB - [TestEntity] at TestFile.kt:1:1 - Signature=TestEntitySignature
TestSmellC - [TestEntity] at TestFile.kt:1:1 - Signature=TestEntitySignature
""".trimIndent()
assertThat(report.render(detektion)).isEqualTo(renderedText)
Expand Down

0 comments on commit fcdc20e

Please sign in to comment.