Skip to content

Commit

Permalink
Merge remote-tracking branch 'detekt/main' into feature/5192-multi-ru…
Browse files Browse the repository at this point in the history
…le-formatting
  • Loading branch information
chao2zhang committed May 27, 2023
2 parents 8373fce + 6f166ec commit 8690bda
Show file tree
Hide file tree
Showing 104 changed files with 12,873 additions and 1,550 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/detekt-with-type-resolution.yaml
Expand Up @@ -37,7 +37,7 @@ jobs:
arguments: :detekt-cli:runWithArgsFile

- name: Upload SARIF to GitHub using the upload-sarif action
uses: github/codeql-action/upload-sarif@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2
uses: github/codeql-action/upload-sarif@0225834cc549ee0ca93cb085b92954821a145866 # v2
if: success() || failure()
with:
sarif_file: build/detekt-report.sarif
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
arguments: detektMain detektTest detektFunctionalTest detektTestFixtures detektReportMergeSarif --continue

- name: Upload SARIF to GitHub using the upload-sarif action
uses: github/codeql-action/upload-sarif@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2
uses: github/codeql-action/upload-sarif@0225834cc549ee0ca93cb085b92954821a145866 # v2
if: success() || failure()
with:
sarif_file: build/reports/detekt/merge.sarif
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Expand Up @@ -10,6 +10,6 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@ba790c862c380240c6d5e7427be5ace9a05c754b # v4
- uses: actions/labeler@0776a679364a9a16110aac8d0f40f5e11009e327 # v4
with:
repo-token: "${{ secrets.DETEKT_CI_GITHUB_USER_TOKEN }}"
2 changes: 1 addition & 1 deletion .github/workflows/website.yaml
Expand Up @@ -48,7 +48,7 @@ jobs:
run: yarn build

- name: Deploy GitHub Pages (only on main)
uses: JamesIves/github-pages-deploy-action@ba1486788b0490a235422264426c45848eac35c6 # tag=v4
uses: JamesIves/github-pages-deploy-action@22a6ee251d6f13c6ab1ecb200d974f1a6feb1b8d # v4
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
branch: gh-pages
Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/Versions.kt
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget

object Versions {

const val DETEKT: String = "1.23.0-RC3"
const val DETEKT: String = "1.23.0"
const val SNAPSHOT_NAME: String = "main"
val JVM_TARGET: JvmTarget = JvmTarget.JVM_1_8

Expand Down
17 changes: 11 additions & 6 deletions config/detekt/detekt.yml
Expand Up @@ -155,12 +155,17 @@ style:
active: true
ForbiddenComment:
active: true
values:
- 'TODO:'
- 'FIXME:'
- 'STOPSHIP:'
- '@author'
- '@requiresTypeResolution'
comments:
- value: 'FIXME:'
reason: 'Forbidden FIXME todo marker in comment, please fix the problem.'
- value: 'STOPSHIP:'
reason: 'Forbidden STOPSHIP todo marker in comment, please address the problem before shipping the code.'
- value: 'TODO:'
reason: 'Forbidden TODO todo marker in comment, please do the changes.'
- value: '@author'
reason: 'Authors are not recorded in KDoc.'
- value: '@requiresTypeResolution'
reason: 'Use @RequiresTypeResolution annotation on the class instead.'
excludes: ['**/detekt-rules-style/**/ForbiddenComment.kt']
ForbiddenImport:
active: true
Expand Down
12 changes: 7 additions & 5 deletions detekt-core/src/main/resources/default-detekt-config.yml
Expand Up @@ -572,12 +572,14 @@ style:
value: 'java.lang.annotation.Inherited'
ForbiddenComment:
active: true
values:
- 'FIXME:'
- 'STOPSHIP:'
- 'TODO:'
comments:
- reason: 'Forbidden FIXME todo marker in comment, please fix the problem.'
value: 'FIXME:'
- reason: 'Forbidden STOPSHIP todo marker in comment, please address the problem before shipping the code.'
value: 'STOPSHIP:'
- reason: 'Forbidden TODO todo marker in comment, please do the changes.'
value: 'TODO:'
allowedPatterns: ''
customMessage: ''
ForbiddenImport:
active: false
imports: []
Expand Down
2 changes: 2 additions & 0 deletions detekt-core/src/main/resources/deprecation.properties
Expand Up @@ -15,6 +15,8 @@ potential-bugs>IgnoredReturnValue>restrictToAnnotatedMethods=Use `restrictToConf
potential-bugs>LateinitUsage>excludeAnnotatedProperties=Use `ignoreAnnotated` instead
potential-bugs>MissingWhenCase=Rule deprecated as compiler performs this check by default
potential-bugs>RedundantElseInWhen=Rule deprecated as compiler performs this check by default
style>ForbiddenComment>customMessage=Use `comments` and provide `reason` against each `value`.
style>ForbiddenComment>values=Use `comments` instead, make sure you escape your text for Regular Expressions.
style>ForbiddenPublicDataClass=Rule migrated to `libraries` ruleset plugin
style>FunctionOnlyReturningConstant>excludeAnnotatedFunction=Use `ignoreAnnotated` instead
style>LibraryCodeMustSpecifyReturnType=Rule migrated to `libraries` ruleset plugin
Expand Down
145 changes: 0 additions & 145 deletions detekt-core/src/test/resources/cases/ComplexClass.kt

This file was deleted.

@@ -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(),
)
}
4 changes: 4 additions & 0 deletions detekt-formatting/src/main/resources/config/config.yml
Expand Up @@ -147,6 +147,10 @@ formatting:
NoSemicolons:
active: true
autoCorrect: true
NoSingleLineBlockComment:
active: false
autoCorrect: true
indentSize: 4
NoTrailingSpaces:
active: true
autoCorrect: true
Expand Down
@@ -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)
}
}
9 changes: 3 additions & 6 deletions detekt-gradle-plugin/build.gradle.kts
Expand Up @@ -12,7 +12,7 @@ plugins {
idea
alias(libs.plugins.pluginPublishing)
// We use this published version of the detekt plugin to self analyse this project.
id("io.gitlab.arturbosch.detekt") version "1.22.0"
id("io.gitlab.arturbosch.detekt") version "1.23.0"
}

repositories {
Expand Down Expand Up @@ -70,16 +70,13 @@ dependencies {
compileOnly(libs.kotlin.gradle)
compileOnly(libs.kotlin.gradlePluginApi)
testFixturesCompileOnly("org.jetbrains:annotations:24.0.1")
implementation(libs.sarif4k) {
exclude("org.jetbrains.kotlin")
}
compileOnly("io.gitlab.arturbosch.detekt:detekt-cli:1.22.0")
compileOnly("io.gitlab.arturbosch.detekt:detekt-cli:1.23.0")

testKitRuntimeOnly(libs.kotlin.gradle)
testKitJava17RuntimeOnly(libs.android.gradle.maxSupported)

// We use this published version of the detekt-formatting to self analyse this project.
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.22.0")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.0")
}

gradlePlugin {
Expand Down
2 changes: 1 addition & 1 deletion detekt-gradle-plugin/settings.gradle.kts
Expand Up @@ -13,5 +13,5 @@ dependencyResolutionManagement {
}

plugins {
id("com.gradle.enterprise") version "3.13.2"
id("com.gradle.enterprise") version "3.13.3"
}
@@ -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
}

0 comments on commit 8690bda

Please sign in to comment.