Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
paul-dingemans opened this issue Feb 1, 2024 · 0 comments · Fixed by #2552
Closed

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

paul-dingemans opened this issue Feb 1, 2024 · 0 comments · Fixed by #2552
Milestone

Comments

@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Feb 1, 2024

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 #2345 (comment) the solution could be to split the property-naming rule and extract part of the logic to a new rule backing-property. Requirements:

  • property-naming rule should ignore properties for which the name starts with _ as this will be handled by backing-property rule
  • backing-property rule will be identical to logic which is currently implemented in property-naming in case of intellij_idea or ktlint_official code styles. In case of android_studio code style, the modifier is ignored.
@paul-dingemans paul-dingemans added this to the 1.2 milestone Feb 1, 2024
paul-dingemans added a commit that referenced this issue Feb 13, 2024
Extract `backing-property-name` from `property-naming` rule. This allows users to disable this rule, but keep the `property-naming` rule in place.

 For `android_studio` code style the restrictions regarding the modifier of the correlated property or function is ignored entirely as the Android Kotlin Styleguide does not require it to be public.

 Closes #2528
paul-dingemans added a commit that referenced this issue Feb 14, 2024
…2552)

Extract `backing-property-name` from `property-naming` rule. This allows users to disable this rule, but keep the `property-naming` rule in place.

 For `android_studio` code style the restrictions regarding the modifier of the correlated property or function is ignored entirely as the Android Kotlin Styleguide does not require it to be public.

 Closes #2528
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant