Skip to content
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

Bump KtLint to 0.44.0 and add UnnecessaryParenthesesBeforeTrailingLamda rule #4630

Merged
merged 8 commits into from Mar 19, 2022
6 changes: 5 additions & 1 deletion detekt-formatting/build.gradle.kts
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation(libs.ktlint.rulesetExperimental) {
exclude(group = "org.jetbrains.kotlin")
}
implementation(libs.ktlint.microutilsKotlinLoggingJvm)

testImplementation(projects.detektTest)
testImplementation(libs.assertj)
Expand All @@ -22,7 +23,10 @@ tasks.build { finalizedBy(":detekt-generator:generateDocumentation") }

val depsToPackage = setOf(
"org.ec4j.core",
"com.pinterest.ktlint"
"com.pinterest.ktlint",
"com.pinterest.ktlint",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fuuuu

"io.github.microutils",
"org.slf4j",
)

tasks.jar {
Expand Down
@@ -1,5 +1,6 @@
package io.gitlab.arturbosch.detekt.formatting

import com.pinterest.ktlint.core.EditorConfig.Companion.fromMap
import com.pinterest.ktlint.core.KtLint
import com.pinterest.ktlint.core.Rule.VisitorModifier.RunAsLateAsPossible
import com.pinterest.ktlint.core.Rule.VisitorModifier.RunOnRootNodeOnly
Expand Down Expand Up @@ -85,6 +86,13 @@ abstract class FormattingRule(config: Config) : Rule(config) {
if (ruleShouldOnlyRunOnFileNode(node)) {
return
}

// KtLint 0.44.0 is assuming that KtLint.EDITOR_CONFIG_USER_DATA_KEY is available on all the nodes.
// If not, it crashes with a NPE. Here we're patching their behavior.
if (node.getUserData(KtLint.EDITOR_CONFIG_USER_DATA_KEY) == null) {
node.putUserData(KtLint.EDITOR_CONFIG_USER_DATA_KEY, fromMap(emptyMap()))
}

wrapping.visit(node, autoCorrect) { offset, message, _ ->
val (line, column) = positionByOffset(offset)
val location = Location(
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Expand Up @@ -3,6 +3,7 @@ dokka = "1.6.10"
jacoco = "0.8.7"
kotlin = "1.6.10"
ktlint = "0.44.0"
microutilsKotlinLoggingJvm = "2.1.21"
spek = "2.0.18"
junit = "5.8.2"

Expand All @@ -26,6 +27,7 @@ android-gradle = "com.android.tools.build:gradle:7.1.2"
ktlint-core = { module = "com.pinterest.ktlint:ktlint-core", version.ref = "ktlint" }
ktlint-rulesetStandard = { module = "com.pinterest.ktlint:ktlint-ruleset-standard", version.ref = "ktlint" }
ktlint-rulesetExperimental = { module = "com.pinterest.ktlint:ktlint-ruleset-experimental", version.ref = "ktlint" }
ktlint-microutilsKotlinLoggingJvm = { module = "io.github.microutils:kotlin-logging-jvm", version.ref = "microutilsKotlinLoggingJvm" }

dokka-jekyll = { module = "org.jetbrains.dokka:jekyll-plugin", version.ref = "dokka"}

Expand Down