Skip to content

Commit

Permalink
Suppress property-name rule for ObjectPropertyName or `PrivatePro…
Browse files Browse the repository at this point in the history
…pertyName` (#2643)

When Intellij IDEA suppressions `ObjectPropertyName` or `PrivatePropertyName` are used, then also suppress ktlint `property-naming` rule.

Closes #2612
  • Loading branch information
paul-dingemans committed Apr 23, 2024
1 parent 2dbeb9f commit c9a97af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion documentation/snapshot/docs/rules/standard.md
Expand Up @@ -586,7 +586,7 @@ Enforce naming of property.
}
```

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

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

Expand Down
Expand Up @@ -43,6 +43,8 @@ internal object SuppressionLocatorBuilder {
"PackageName" to "standard:package-name",
"PropertyName" to "standard:property-naming",
"ConstPropertyName" to "standard:property-naming",
"ObjectPropertyName" to "standard:property-naming",
"PrivatePropertyName" to "standard:property-naming",
"UnusedImport" to "standard:no-unused-imports",
)
private val SUPPRESS_ANNOTATIONS = setOf("Suppress", "SuppressWarnings")
Expand Down
Expand Up @@ -286,4 +286,26 @@ class PropertyNamingRuleTest {
""".trimIndent()
propertyNamingRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Issue 2612 - Given a property name suppressed via 'PrivatePropertyName' then also suppress the ktlint violation`() {
val code =
"""
class Foo {
@Suppress("PrivatePropertyName")
private val Bar = "Bar"
}
""".trimIndent()
propertyNamingRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Issue 2612 - Given a property name suppressed via 'ObjectPropertyName' then also suppress the ktlint violation`() {
val code =
"""
@Suppress("ObjectPropertyName")
private const val _Foo_Bar = ""
""".trimIndent()
propertyNamingRuleAssertThat(code).hasNoLintViolations()
}
}

0 comments on commit c9a97af

Please sign in to comment.