From 9ba1d0c0cce380428c51db112c6c5ba4cf84536e Mon Sep 17 00:00:00 2001 From: Paul Dingemans Date: Tue, 3 Sep 2024 18:40:55 +0200 Subject: [PATCH] Suppress `backing-property-naming` rule with `@Suppress("LocalVariableName")` (#2785) * Suppress `backing-property-naming` rule with `@Suppress("LocalVariableName")` * Suppress `backing-property-naming` rule with `@Suppress("LocalVariableName")` Closes #2779 --- .../rule/engine/internal/SuppressionLocator.kt | 1 + .../standard/rules/BackingPropertyNamingRuleTest.kt | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocator.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocator.kt index 85c5e66231..06be443451 100644 --- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocator.kt +++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocator.kt @@ -261,6 +261,7 @@ internal class SuppressionLocator( "RemoveCurlyBracesFromTemplate" to listOf("standard:string-template"), "ClassName" to listOf("standard:class-naming"), "FunctionName" to listOf("standard:function-naming"), + "LocalVariableName" to listOf("standard:backing-property-naming"), "PackageName" to listOf("standard:package-name"), "PropertyName" to listOf("standard:property-naming", "standard:backing-property-naming"), "ConstPropertyName" to listOf("standard:property-naming"), 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 6d33a7cdcf..ce3d3a1ebf 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 @@ -359,4 +359,17 @@ class BackingPropertyNamingRuleTest { """.trimIndent() backingPropertyNamingRuleAssertThat(code).hasNoLintViolations() } + + @Test + fun `Issue 2779 - Given a property name suppressed via 'LocalVariableName' then also suppress the ktlint violation`() { + val code = + """ + @Suppress("LocalVariableName") + fun test() { + val _test = "test" + println(_test) + } + """.trimIndent() + backingPropertyNamingRuleAssertThat(code).hasNoLintViolations() + } }