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

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

Closed
tbroyer opened this issue Jun 24, 2019 · 11 comments
Closed

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

tbroyer opened this issue Jun 24, 2019 · 11 comments

Comments

@tbroyer
Copy link
Contributor

tbroyer commented Jun 24, 2019

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)

@amadeu01
Copy link

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

@nedtwigg
Copy link
Member

nedtwigg commented Aug 30, 2019

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);

tbroyer added a commit to gwtproject/gwt-event that referenced this issue Sep 29, 2019
due to diffplug/spotless#409 and diffplug/spotless#419

Update to Ktlint 0.34.2 and enable experimental rules.
@nedtwigg
Copy link
Member

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

@aphexcx
Copy link

aphexcx commented Dec 7, 2020

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?

@nedtwigg
Copy link
Member

nedtwigg commented Dec 7, 2020

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.

@nedtwigg
Copy link
Member

nedtwigg commented Feb 9, 2021

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.

@nedtwigg
Copy link
Member

nedtwigg commented Dec 5, 2021

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

@st-hocnguyen
Copy link

st-hocnguyen commented Mar 15, 2022

Any progress on this?

@nedtwigg
Copy link
Member

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

@alexvanyo
Copy link
Contributor

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

@nedtwigg
Copy link
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
Projects
None yet
Development

No branches or pull requests

6 participants