nbadal / ktlint-intellij-plugin

Ktlint plugin for IntelliJ IDEA + Android Studio
MIT License
150 stars 22 forks source link

Compatibility with composable function names #524

Closed EchoEllet closed 1 month ago

EchoEllet commented 1 month ago

First of all, I would like to thank you for your efforts on this project.

Currently, if you are using Compose multiplatform or Compose Desktop or any project that use Composable functions, by default it will be against the naming conventions and IntelliJ IDEA will suggest to rename the function, this can be fixed by using Android Studio or installing Compose Multipaltform IntelliJ IDEA plugin, but when using Ktlint IntelliJ IDEA plugin it would give the following warning:

image

Which can be ignored using:

@Suppress("ktlint:standard:function-naming")
@Composable
fun App() {}

Or add it to each Gradle Module that uses Compose or to the whole project if all the modules use Compose Desktop, I'm not sure how but is it possible to support Compose projects? I haven't tried out KtLint IntelliJ IDEA plugin with Android Studio so maybe it already has this feature by default

Thank you once again.

paul-dingemans commented 1 month ago

Please see ktlint documentation for configuring this rule: https://pinterest.github.io/ktlint/latest/rules/standard/#function-naming

EchoEllet commented 1 month ago

Please see ktlint documentation for configuring this rule: https://pinterest.github.io/ktlint/latest/rules/standard/#function-naming

Thank you, I'm not sure but if there is a way to detect if this a compose project or maybe Compose Desktop IDE plugin installed then it will be used or added automatically

paul-dingemans commented 1 month ago

In next version of the plugin, I have already changed the preference screen slightly to mention Jetpack Compose as a popular ruleset.

Screenshot 2024-05-21 at 18 58 38

Technically, it is possible to scan all kotlin files for the existence of an import for a Compose package. If so, and the Jetpack Compose ruleset is not used, the plugin could than emit a message like "It looks that you are using Compose. Do you know that a Jetpack Compose ruleset for ktlint exists?". But the user will still need to download the Jetpack Compose ruleset, and configure it manually. The intellij plugin will never be able to install the Jetpack Compose ruleset automatically, as I do not want the project to be dependend on external projects (other than ktlint of course).

EchoEllet commented 1 month ago

It could ignore the message without using the lint but then this will only work on the IntelliJ IDEA Plugin and not using the KtLint command

paul-dingemans commented 1 month ago

It could ignore the message without using the lint but then this will only work on the IntelliJ IDEA Plugin and not using the KtLint command

?? No clue what you exactly mean.

The plugin is a wrapper around ktlint core (which is also use to build the Ktlint CLI). Neither plugin, nor ktlint CLI wil get functionality to download external rulesets.