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

Using this plugin with the official IntelliJ IDE plugin #744

Open
wejrox opened this issue Jan 22, 2024 · 3 comments
Open

Using this plugin with the official IntelliJ IDE plugin #744

wejrox opened this issue Jan 22, 2024 · 3 comments

Comments

@wejrox
Copy link

wejrox commented Jan 22, 2024

Summary

I've got a few projects that use this plugin to format our code before commit.
We also use the Ktlint IntelliJ plugin with auto formatting to fix code violations on-save before commit.

Problem

Currently, the rules applied by that plugin don't align with the rules applied by this plugin.
I'd like to make the IDE plugin use the rules in use by this plugin.

Environment

ktlint-gradle version 11.6.1
Android Studio 2023.1.1
Android Studio ktlint plugin (According to the docs, the plugin currently runs with ktlint version 1.1.0 and can use .editorconfig)

What I've tried

I've tried to use the ktlintApplyToIdea to export the rules and apply them to the IDE, but I'm receiving

> Task :ktlintApplyToIdea
Skipping ktlintApplyToIdea. The applyToIDEA functionality was removed from ktlint in 0.47.0. Use .editorconfig to synchronize formatting rules between IDEA and ktlint.

BUILD SUCCESSFUL in 219ms
1 actionable task: 1 executed

Because I don't know the default rules, I don't have the information required to Use .editorconfig to synchronize formatting rules between IDEA and ktlint..

Request

Is there some documentation on how I can export an xml ruleset, or guidance on this?

@wejrox wejrox changed the title Setting up IntelliJ rules to match the plugin Using this plugin with the official IntelliJ IDE plugin Jan 22, 2024
@wakingrufus
Copy link
Collaborator

I think this page will help you: https://pinterest.github.io/ktlint/1.1.1/rules/code-styles/

@wejrox
Copy link
Author

wejrox commented Jan 22, 2024

Unfortunately, that page tells me how I can override the code style rules, but I don't know which rules ktlint-gradle uses by default.

I want to force my IDE to use the same rules as ktlint-gradle is applying, so I need to konw what those default rules are.

@wakingrufus
Copy link
Collaborator

the code style used by default is whichever the underlying version of ktlint is using. So for ktlint version < 1 it is intellij style, and for >=1 it is ktlint_official.

as for the configuration of specfic rules, again, this is tied to the version of ktlint being used.

since you are using ktlint-gradle 11.6.1, the version of ktlint it is using by default is 0.47.1. I recommend changing this to match the version of ktlint your intellij plugin is using.

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