pinterest / ktlint

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

Extract backing property from `property-naming` rule to separate rule #2528

Closed paul-dingemans closed 7 months ago

paul-dingemans commented 8 months ago

The property-naming also contains logic to check backing properties.

Kotlin Coding Conventions clear states that:

If a class has two properties which are conceptually the same but one is part of a public API and another is an implementation detail, use an underscore as the prefix for the name of the private property:

When a backing property is needed, its name should exactly match that of the real property except prefixed with an underscore. Android Kotlin style guide is less explicit:

When a backing property is needed, its name should exactly match that of the real property except prefixed with an underscore.

Several users have requested to loosen the restrictions regarding the modifier of the base property:

As Originally posted by @paul-dingemans in https://github.com/pinterest/ktlint/issues/2345#issuecomment-1808943854 the solution could be to split the property-naming rule and extract part of the logic to a new rule backing-property. Requirements: