Skip to content

Allow enabling experimental and/or custom ruleset for ktlint #409

Description

@tbroyer

kotlin and kotlinGradle (in Gradle plugin, haven't looked at other usages or Spotless) don't seem to allow using the experimental ruleset of Ktlint (enabling import ordering and indentation rules), and/or custom rulesets (e.g. to re-enable the "no wildcard import" rule that's now disabled by default in Ktlint 0.33.0)

Activity

  1. amadeu01 commented on Aug 30, 2019

    @amadeu01

    @nedtwigg Do you know who could answer that? or, this feature is not possible currently?

  2. nedtwigg commented on Aug 30, 2019

    @nedtwigg
    Member

    It's not possible currently, but could be added. Here's the code that would need to change:

    // String KtLint::format(String input, Iterable<RuleSet> rules, Function2 errorCallback)
    // first, we get the standard rules
    Class<?> standardRuleSetProviderClass = classLoader.loadClass(pkg + ".ktlint.ruleset.standard.StandardRuleSetProvider");
    Object standardRuleSet = standardRuleSetProviderClass.getMethod("get").invoke(standardRuleSetProviderClass.newInstance());
    Iterable<?> ruleSets = Collections.singletonList(standardRuleSet);

  3. nedtwigg commented on Feb 13, 2020

    @nedtwigg
    Member

    Fixing this with reflection is doable, but tricky. It would be a lot easier with #524.

  4. aphexcx commented on Dec 7, 2020

    @aphexcx

    Hi there! Curious if there's an update on this. I really want to use spotless with https://github.com/cqfn/diKTat (which is a custom ktlint ruleset along with its own config.)

    If this isn't usable yet, perhaps I could help. I've read a bunch of other issues to figure out how hard this would be to implement myself, possibly as a custom Step that calls the diKTat formatter?

  5. nedtwigg commented on Dec 7, 2020

    @nedtwigg
    Member

    Happy to take a PR which adds support for custom ktlint rulesets, and/or happy to take a PR with diKTat support. The challenge for both is that the integration code is currently written using reflection, though that can be fixed with #524.

    If you decide submit a PR for either, I would recommend doing the documentation first, and submitting a draft PR with the documentation. Then build to the docs.

  6. nedtwigg commented on Feb 9, 2021

    @nedtwigg
    Member

    diKTat is a one way to accomplish this, and it is now available in plugin-gradle 5.10.0 and plugin-maven 2.8.0.

  7. nedtwigg commented on Dec 5, 2021

    @nedtwigg
    Member

    Now that #1012 has merged, it should be easier to build this if anybody wants to contribute a PR.

  8. st-hocnguyen commented on Mar 15, 2022

    @st-hocnguyen

    Any progress on this?

  9. nedtwigg commented on Mar 28, 2022

    @nedtwigg
    Member

    @st-hocnguyen nope, PR's welcome :)

  10. alexvanyo commented on Apr 18, 2022

    @alexvanyo
    Contributor

    I've opened #1168 to attempt to partially address this issue, by adding the ability to enable the experimental ruleset for ktlint.

  11. nedtwigg commented on Apr 23, 2022

    @nedtwigg
    Member

    Support for experimental rules was added in plugin-gradle 6.5.0. If someone wants custom rulesets, please open a new issue describing the desired functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions