Skip to content

Commit c9a97af

Browse files
Suppress property-name rule for ObjectPropertyName or PrivatePropertyName (#2643)
When Intellij IDEA suppressions `ObjectPropertyName` or `PrivatePropertyName` are used, then also suppress ktlint `property-naming` rule. Closes #2612
1 parent 2dbeb9f commit c9a97af

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

documentation/snapshot/docs/rules/standard.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ Enforce naming of property.
586586
}
587587
```
588588

589-
This rule can also be suppressed with the IntelliJ IDEA inspection suppression `PropertyName` or `ConstPropertyName`.
589+
This rule is suppressed whenever the IntelliJ IDEA inspection suppression `PropertyName`, `ConstPropertyName`, `ObjectPropertyName` or `PrivatePropertyName` is used.
590590

591591
Rule id: `property-naming` (`standard` rule set)
592592

ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocatorBuilder.kt

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ internal object SuppressionLocatorBuilder {
4343
"PackageName" to "standard:package-name",
4444
"PropertyName" to "standard:property-naming",
4545
"ConstPropertyName" to "standard:property-naming",
46+
"ObjectPropertyName" to "standard:property-naming",
47+
"PrivatePropertyName" to "standard:property-naming",
4648
"UnusedImport" to "standard:no-unused-imports",
4749
)
4850
private val SUPPRESS_ANNOTATIONS = setOf("Suppress", "SuppressWarnings")

ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRuleTest.kt

+22
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,26 @@ class PropertyNamingRuleTest {
286286
""".trimIndent()
287287
propertyNamingRuleAssertThat(code).hasNoLintViolations()
288288
}
289+
290+
@Test
291+
fun `Issue 2612 - Given a property name suppressed via 'PrivatePropertyName' then also suppress the ktlint violation`() {
292+
val code =
293+
"""
294+
class Foo {
295+
@Suppress("PrivatePropertyName")
296+
private val Bar = "Bar"
297+
}
298+
""".trimIndent()
299+
propertyNamingRuleAssertThat(code).hasNoLintViolations()
300+
}
301+
302+
@Test
303+
fun `Issue 2612 - Given a property name suppressed via 'ObjectPropertyName' then also suppress the ktlint violation`() {
304+
val code =
305+
"""
306+
@Suppress("ObjectPropertyName")
307+
private const val _Foo_Bar = ""
308+
""".trimIndent()
309+
propertyNamingRuleAssertThat(code).hasNoLintViolations()
310+
}
289311
}

0 commit comments

Comments
 (0)