diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2f70d63d3f..1cb28e40c5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,14 +3,14 @@ java-compilation = "21" # The java-target version is the lowest supported LTS version of Java. Jar's produced are bytecode compatible with this version. java-target = "8" -kotlin = "2.0.0" -kotlinDev = "2.0.0" +kotlin = "2.0.10" +kotlinDev = "2.0.10" [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } checksum = "org.gradle.crypto.checksum:1.4.0" shadow = "com.gradleup.shadow:8.3.0" -kotlinx-binary-compatibiltiy-validator = "org.jetbrains.kotlinx.binary-compatibility-validator:0.16.2" +kotlinx-binary-compatibiltiy-validator = "org.jetbrains.kotlinx.binary-compatibility-validator:0.16.3" [libraries] kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" } @@ -20,7 +20,7 @@ clikt = "com.github.ajalt.clikt:clikt:4.4.0" dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.20" ec4j = "org.ec4j.core:ec4j-core:0.3.0" logging = "io.github.oshai:kotlin-logging-jvm:7.0.0" -slf4j = "org.slf4j:slf4j-simple:2.0.13" +slf4j = "org.slf4j:slf4j-simple:2.0.15" poko = "dev.drewhamilton.poko:poko-gradle-plugin:0.16.0" # Use logback-classic as the logger for kotlin-logging / slf4j as it allow changing the log level at runtime. # TODO: Update "renovate.json" once logback-classic is updated to 1.4 (once java8 support for ktlint is dropped) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt index cc81eda298..ce6118bb44 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt @@ -4,6 +4,7 @@ import com.pinterest.ktlint.rule.engine.core.api.AutocorrectDecision import com.pinterest.ktlint.rule.engine.core.api.ElementType.FUN import com.pinterest.ktlint.rule.engine.core.api.ElementType.IDENTIFIER import com.pinterest.ktlint.rule.engine.core.api.ElementType.INTERNAL_KEYWORD +import com.pinterest.ktlint.rule.engine.core.api.ElementType.OVERRIDE_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.PRIVATE_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ElementType.PROTECTED_KEYWORD @@ -53,7 +54,10 @@ public class BackingPropertyNamingRule : property .findChildByType(IDENTIFIER) ?.takeIf { it.text.startsWith("_") } - ?.let { identifier -> + ?.takeUnless { + // Do not report overridden properties as they can only be changed by changing the base property + it.treeParent.hasModifier(OVERRIDE_KEYWORD) + }?.let { identifier -> visitBackingProperty(identifier, emit) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRuleTest.kt index 40cca61c9d..6d33a7cdcf 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRuleTest.kt @@ -345,4 +345,18 @@ class BackingPropertyNamingRuleTest { """.trimIndent() backingPropertyNamingRuleAssertThat(code).hasNoLintViolations() } + + @Test + fun `Issue 2748 - Given an override property with name starting with '_' then do not report a violation`() { + val code = + """ + // The property "__foo" in example below can be defined in an external dependency, which can not be changed. Even in case it is + // a (internal) dependency that can be changed, the violation should only be reported at the base property, but on the overrides + val fooBar = + object : FooBar { + override val __foo = "foo" + } + """.trimIndent() + backingPropertyNamingRuleAssertThat(code).hasNoLintViolations() + } }