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

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

Closed
mxalbert1996 opened this issue Apr 16, 2024 · 3 comments
Closed

Comments

@mxalbert1996
Copy link

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

  • Version of ktlint used: 1.2.1
  • Relevant parts of the .editorconfig settings
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): org.jlleitschuh.gradle.ktlint 12.1.0
  • Version of Gradle used (if applicable): 8.6
  • Operating System and version: macOS 14.4.1
@paul-dingemans
Copy link
Collaborator

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
Copy link
Author

mxalbert1996 commented Apr 16, 2024

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
Copy link
Author

Opened #2637.

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

No branches or pull requests

2 participants