pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.16k stars 504 forks source link

Add an option to ignore private property names start with `_` #2326

Closed Goooler closed 11 months ago

Goooler commented 11 months ago

Expected Behavior

We can ignore private properties like Foo._foo, which start with _

class Foo {
    private var _foo = "foo"

    fun bar() {
        _foo = "bar"
    }
}

Current Behavior

Using CLI:

ktlint Foo.kt   
/Users/goooler/StudioProjects/lawnicons/Foo.kt:2:17: Property name should start with a lowercase letter and use camel case (standard:property-naming)

Summary error count (descending) by rule:
  standard:property-naming: 1

EditorConfig file:

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ij_kotlin_imports_layout = *
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ktlint_code_style = intellij_idea

Additional information

Goooler commented 11 months ago

Although we can add ktlint_standard_property-naming = disabled rule to suppress all property checks, I just want to ignore private properties here.

Goooler commented 11 months ago

I missed something refs to Foo._foo, that sounds make sense.

class Foo {
    private var _foo = "foo"

    val foo: String get() = _foo

    fun bar() {
        _foo = "bar"
    }
}