Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'detekt/main' into feature/5192-multi-ru…
…le-formatting
- Loading branch information
Showing
104 changed files
with
12,871 additions
and
1,550 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
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
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
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
This file was deleted.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
...c/main/kotlin/io/gitlab/arturbosch/detekt/formatting/wrappers/NoSingleLineBlockComment.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,28 @@ | ||
package io.gitlab.arturbosch.detekt.formatting.wrappers | ||
|
||
import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty | ||
import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY | ||
import com.pinterest.ktlint.ruleset.standard.rules.NoSingleLineBlockCommentRule | ||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.api.config | ||
import io.gitlab.arturbosch.detekt.api.internal.AutoCorrectable | ||
import io.gitlab.arturbosch.detekt.api.internal.Configuration | ||
import io.gitlab.arturbosch.detekt.formatting.FormattingRule | ||
|
||
/** | ||
* See [ktlint docs](https://pinterest.github.io/ktlint/rules/experimental/#no-single-line-block-comments) for documentation. | ||
*/ | ||
@AutoCorrectable(since = "1.23.0") | ||
class NoSingleLineBlockComment(config: Config) : FormattingRule(config) { | ||
|
||
override val wrapping = NoSingleLineBlockCommentRule() | ||
override val issue = issueFor("Reports single block line comments") | ||
|
||
@Configuration("indentation size") | ||
private val indentSize by config(4) | ||
|
||
override fun overrideEditorConfigProperties(): Map<EditorConfigProperty<*>, String> = | ||
mapOf( | ||
INDENT_SIZE_PROPERTY to indentSize.toString(), | ||
) | ||
} |
37 changes: 37 additions & 0 deletions
37
...ng/src/test/kotlin/io/gitlab/arturbosch/detekt/formatting/NoSingleLineBlockCommentSpec.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,37 @@ | ||
package io.gitlab.arturbosch.detekt.formatting | ||
|
||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.formatting.wrappers.CommentWrapping | ||
import io.gitlab.arturbosch.detekt.formatting.wrappers.NoSingleLineBlockComment | ||
import io.gitlab.arturbosch.detekt.test.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class NoSingleLineBlockCommentSpec { | ||
@Test | ||
fun `Given a single documentation comment that start starts and end on a same line`() { | ||
val code = """ | ||
/** Some comment */ | ||
""".trimIndent() | ||
assertThat(NoSingleLineBlockComment(Config.empty).lint(code)).isEmpty() | ||
} | ||
|
||
@Test | ||
fun `Given a single block comment that start starts and end on a same line`() { | ||
val code = """ | ||
/* Some comment */ | ||
""".trimIndent() | ||
assertThat(NoSingleLineBlockComment(Config.empty).lint(code)).hasSize(1) | ||
} | ||
|
||
@Test | ||
fun `Given a block comment followed by a code element on the same line as the block`() { | ||
val code = """ | ||
/* Some comment 1 */ val foo1 = "foo1" | ||
/* Some comment 2 */val foo2 = "foo2" | ||
/* Some comment 3 */ fun foo3() = "foo3" | ||
/* Some comment 4 */fun foo4() = "foo4" | ||
""".trimIndent() | ||
|
||
assertThat(CommentWrapping(Config.empty).lint(code)).hasSize(4) | ||
} | ||
} |
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
23 changes: 19 additions & 4 deletions
23
detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/report/SarifReportMerger.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,19 +1,34 @@ | ||
package io.gitlab.arturbosch.detekt.report | ||
|
||
import io.github.detekt.sarif4k.SarifSerializer | ||
import groovy.json.JsonOutput | ||
import groovy.json.JsonSlurper | ||
import java.io.File | ||
|
||
private typealias JsonObject = MutableMap<String, Any?> | ||
|
||
/** | ||
* A naive implementation to merge SARIF assuming all inputs are written by detekt. | ||
*/ | ||
object SarifReportMerger { | ||
|
||
fun merge(inputs: Collection<File>, output: File) { | ||
val sarifs = inputs.filter { it.exists() }.map { | ||
SarifSerializer.fromJson(it.readText()) | ||
@Suppress("UNCHECKED_CAST") | ||
(JsonSlurper().parse(it) as JsonObject) | ||
} | ||
val mergedResults = sarifs.flatMap { it.runs.single().results.orEmpty() } | ||
val mergedSarif = sarifs[0].copy(runs = listOf(sarifs[0].runs.single().copy(results = mergedResults))) | ||
output.writeText(SarifSerializer.toJson(mergedSarif)) | ||
val mergedSarif = sarifs[0].apply { this.runs.single().results = mergedResults } | ||
output.writeText(JsonOutput.prettyPrint(JsonOutput.toJson(mergedSarif))) | ||
} | ||
} | ||
|
||
private val JsonObject.runs: List<JsonObject> | ||
@Suppress("UNCHECKED_CAST") | ||
get() = this["runs"] as List<JsonObject> | ||
|
||
private var JsonObject.results: List<JsonObject>? | ||
@Suppress("UNCHECKED_CAST") | ||
get() = this["results"] as List<JsonObject>? | ||
set(value) { | ||
this["results"] = value | ||
} |
Oops, something went wrong.