Repository navigation
Allow enabling experimental and/or custom ruleset for ktlint #409
Description
Activity
@nedtwigg Do you know who could answer that? or, this feature is not possible currently?
It's not possible currently, but could be added. Here's the code that would need to change:
spotless/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
Lines 109 to 114 in 6c7db83
// 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); - added a commit that references this issue
on Sep 29, 2019 Fixing this with reflection is doable, but tricky. It would be a lot easier with #524.
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?
Reacted by Ned Twigg and White RabbitHappy 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.
diKTat is a one way to accomplish this, and it is now available in
plugin-gradle 5.10.0andplugin-maven 2.8.0.Now that #1012 has merged, it should be easier to build this if anybody wants to contribute a PR.
Any progress on this?
@st-hocnguyen nope, PR's welcome :)
I've opened #1168 to attempt to partially address this issue, by adding the ability to enable the experimental ruleset for ktlint.
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.
kotlinandkotlinGradle(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)