nbadal / ktlint-intellij-plugin

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

Configure `Ruleset version` for Plugin via `.editorconfig` file #540

Closed ievgen-kapinos closed 2 weeks ago

ievgen-kapinos commented 2 weeks ago

Hi

On our projects my team uses ktlint-intellij-plugin (dev environment) and jlleitschuh/ktlint-gradle plugin (rarely on dev environment, always on CI/CD server).

In this Gradle plugin we can set ktlint version as described here. That works well, because we can store it in repository and it will be applied automatically in all dev environments and CI/CD.

As for ktlint-intellij-plugin I have to manually set ktlint version via IDE settings in each project. This problem becomes more painful when we have many developers using same project. Also, different projects may use different ktlint version.

Could you consider to add an option to fetch Ruleset version (ktlint version) from .editorconfig file?

I suppose it should be some new custom setting specifically prefixed for your plugin (like Idea has own settings with prefix ij_). So it can be stored in a repo and automatically applied in all dev environments where ktlint-intellij-plugin is installed. If setting is not found, then default behaviour can be used. I suppose now your plugin by default uses some hardcoded ktlint version. In UI it appears as Ruleset version: default (recommended).

Something like this Screenshot 2024-06-20 at 16 13 15

P.S. It is clear that fetching ktlint version from jlleitschuh/ktlint-gradle plugin has no sense.

paul-dingemans commented 2 weeks ago

Could you consider to add an option to fetch Ruleset version (ktlint version) from .editorconfig file?

Please commit file .idea/ktlint-plugin.xml to your version control. In this way, all preferences of the plugin will be shared amongst all developers on the project.

ievgen-kapinos commented 2 weeks ago

Need to try. Thank for the idea.

ievgen-kapinos commented 2 weeks ago

@paul-dingemans thank you for quick respond.

It works. Also I've discovered Idea's feature Required Plugins. So Idea IDE can notify user, if plugin is not installed.

Here what I end up with (notes for those who want to implement the same):

.gitignore - configured manually

.idea/*
!.idea/externalDependencies.xml
!.idea/ktlint-plugin.xml

.idea/externalDependencies.xml - configured via UI.

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ExternalDependencies">
    <plugin id="com.nbadal.ktlint" />
  </component>
</project>

.idea/ktlint-plugin.xml - configured via UI.

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="KtLint plugin">
    <ktlintMode>MANUAL</ktlintMode>
    <ktlintRulesetVersion>V1_0_1</ktlintRulesetVersion>
  </component>
</project>

Keep in mind, files in .idea folder are not updated immediately (after click OK or Apply in Settings UI), but only after IDE quit.

paul-dingemans commented 2 weeks ago

Tnx for sharing back the required plugin settings which indeed might be helpful in cases like you describe. As you now have a working solution, I will close the issue.