pinterest / ktlint

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

Do not report PascalCase top-level constants in property-naming rule #2636

Closed mxalbert1996 closed 2 months ago

mxalbert1996 commented 2 months ago

Expected Behavior

A top-level constant with a name in PascalCase (e.g. private const val SomeConstant = 100) shouldn't be reported as a violation.

I'm using android_studio style and latest stable version of Android Studio (2023.2.1 Patch 2) doesn't report this.

Screenshot 2024-04-16 at 19 10 20

PascalCase is the style recommended by API Guidelines for Jetpack Compose.

By the way, the recommendation also applies to properties of objects, so it would be great to fix that as well, but that case is also reported by AS, though.

Observed Behavior

The following violation is reported: Property name should use the screaming snake case notation when the value can not be changed.

Steps to Reproduce

Simply private const val SomeConstant = 100.

Your Environment

paul-dingemans commented 2 months ago

Ktlint is following the recommendations of Android Kotlin Style Guide when using code_style android_studio.

Based on Baseline style guidelines of Jetpack Compose you should use default kotlin coding style (code_style = intellij_idea). But this results in same violation.

The exception for Singletons, constants, sealed class and enum class values defined in Jetpack Compose can best be dealt with by disabling this rule in the .editorconfig. Defining a separate code style for Jetpack Compose is not something that I consider at this moment.

mxalbert1996 commented 2 months ago

Based on Baseline style guidelines of Jetpack Compose you should use default kotlin coding style (code_style = intellij_idea). But this results in same violation.

Right. I tried in IntelliJ IDEA and it's not reported as well, so this as a conflict between ktlint and IntelliJ IDEA. What is worse is that suppressing the rule using @Suppress("ConstPropertyName") results in a warning ("Redundant suppression") in the IDE. I guess disabling the rule is the only way.

Defining a separate code style for Jetpack Compose is not something that I consider at this moment.

Understandable. Disabling the rule is what I'm doing now, but that also disables the linting of other non-constant properties. It would be great if the naming rule for constants can be separated so that I can disable that rule only.

mxalbert1996 commented 2 months ago

Opened #2637.