-
Notifications
You must be signed in to change notification settings - Fork 460
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
Add support for ktlint to respect .editorconfig #142
Comments
Fixing this will require a change to It will be necessary for the spotless {
kotlin {
ktlint().editorConfig('.editorconfig')
... For an example of how to pass arguments like this in Spotless see ScalaExtension.ScalaFmtConfig. PR's welcome! |
Just a quick remark:
|
Yep! That's why I linked to ScalaExtension.ScalaFmtConfig, because it is an example of that. I don't think it needs to necessarily be |
I was trying to take a look at implementing this. I think the first step might be to get rid of the reflection in |
Or, is it better to add the ktlint dependency as |
I wish it read the |
The reflection is ugly, but necessary, for reasons described in #187. It's fine to add it as a compile dep to work out what the code needs to be, but in the end it needs to be implemented in reflection. Make sure that the |
I was looking in to this a bit. It looks like ktlint only picks up the editorconfig file if it happens to be in the "ktlint working directory". In this case, this would be the spotlesscache? |
I think it would be the project directory, but I'm not positive. Regardless, Spotless would have to know about the |
Any progress on this? |
#469 will unlock this since KtLint 0.34 added a nicer API for passing this on to the formatting step |
I've been working on this, but think I've encountered a bug in KtLint - pinterest/ktlint#605 If this behavior's intentional, Spotless would need to pass the file path and not just the contents to the format call. Note that this might be a good idea to support anyway, as I suspect |
Setting the file path could also make editorconfig support Just Work without needing that upstream fix, as it appears to (for better or worse) eagerly traverse the file system hierarchy up from the source file (if available) searching for an editorconfig file. In most projects, I suspect this would work and just leave a custom step configuration for projects that don't fit this pattern. |
Is the Spotless is fast because of up-to-date checking, but it's still pretty fast even if you disable that aspect (which each Normally we say that a step is
Here's an example of how to unhide the path spotless/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java Lines 119 to 141 in c9dc6fc
The problem is, if you read the file's content from the path, rather than from the If the path is only being used to traverse up the filesystem and find
My suggestion, but I don't know ktlint that wellIf there's a way to preserve up-to-date checking, we should take that route! Even if
I would store the binary or String content of the If you really want to hierarchically find the |
It is hierarchical, but will stop searching as soon as it reaches one that denotes itself as Or we take the easy way and just don't do up-to-date checks. We could make that an opt-in behavior for starters while iterating on re-enabling up-to-date checks too. Thoughts? |
One option is You could extend this to I think a good trade-off between implementation complexity and the universe of user needs:
|
Tracking issue for anybody who wants to remove reflection: #524 |
In the interim, please add a note to the https://github.com/diffplug/spotless/tree/master/plugin-gradle#applying-ktlint-to-kotlin-files section that Also, |
Drive-by documentation improvements are always welcome :) |
I expected this not to depend at all on Spotless, and to simply work since
It doesn't work. Not sure why exactly… |
It seems Spotless always sets the
Why is that? |
The reason Spotless is meddling is to support up-to-date and incremental formatting. In order to implement that, Spotless needs to capture the state of the files and the formatter setup.
Only because no one has done the work to implement it, it is not deliberately nerfed. My unconfirmed guess is that |
Any updates on this? I've tried different approaches and I can't figure out how to make Spotless use the |
Now that #1012 has merged, it should be easier to build this if anybody wants to contribute a PR. |
fyi, this is is likely to get more interest since ktlint's latest release effectively breaks the current |
Happy to take a PR for it :). I've switched to |
From ktlint issue 605:
@ZacSweers indicated in the issue that he no longer works with ktlint. As of that, I will close the ktlint issue. If any other participant in this thread is willing to pick this up, please let me know so that we can create a working solution. |
In Ktlint 0.47 (to be released soon) the parameter 'alternativeEditorConfig |
Is the gist of this discussion that the Secondly, if I do want to add
to
I can also assume the |
I am not familiar with how ktlint is integrated in Spotless. Also it will depend on the specific version whether the Starting from version 0.47, KtLint has properties |
Upvoting this issue. |
Yeah, same problem here, I guess most of people following this issue is on the same boat. |
@nedtwigg to support @get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
val editorConfig: ConfigurableFileCollection // or RegularFileProperty if you want gradle to monitor only a single one // and set convention for it: extension.editorConfig.convention("${project.rootDir}/.editorconfig") and then pass this one to |
I don't know how Gradle convetions work, but happy to take a PR! |
correct gradle conventions to maintain state working example from my plugin.With Kotlin maintenance for semver checking will also decrease a lot as you can do switches with a quite complex operations. |
Published in |
This is working great with both ktlint 0.47.1 and 0.48.1, thanks for the work on this! :) |
The implementation via property |
@paul-dingemans probably related to #1444 instead |
…2.0 (mulk/mulkcms2!16) This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [com.diffplug.spotless:spotless-maven-plugin](https://github.com/diffplug/spotless) | build | minor | `2.31.0` -> `2.32.0` | --- ### Release Notes <details> <summary>diffplug/spotless</summary> ### [`v2.32.0`](https://github.com/diffplug/spotless/blob/HEAD/CHANGES.md#​2320---2023-01-13) ##### Added - Add option `editorConfigFile` for `ktLint` [#​142](diffplug/spotless#142) - **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. - Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#​1441](diffplug/spotless#1441)). - Add YAML support through Jackson ([#​1478](diffplug/spotless#1478)) - Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#​1453](diffplug/spotless#1453)) - Better suggested messages when user's default is set by JVM limitation. ([#​995](diffplug/spotless#995)) ##### Fixed - Support `ktlint` 0.48+ new rule disabling syntax ([#​1456](diffplug/spotless#1456)) fixes ([#​1444](diffplug/spotless#1444)) - Fix subgroups leading catch all matcher. ##### Changes - Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#​1453](diffplug/spotless#1453)) - Bump the dev version of Gradle from `7.5.1` to `7.6` ([#​1409](diffplug/spotless#1409)) - We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` - Breaking changes to Spotless' internal testing infrastructure `testlib` ([#​1443](diffplug/spotless#1443)) - `ResourceHarness` no longer has any duplicated functionality which was also present in `StepHarness` - `StepHarness` now operates on `Formatter` rather than a `FormatterStep` - `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor to handle the file manipulation parts - Standardized that we test exception *messages*, not types, which will ease the transition to linting later on - Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#​1456](diffplug/spotless#1456)) - Switch our publishing infrastructure from CircleCI to GitHub Actions ([#​1462](diffplug/spotless#1462)). - Help wanted for moving our tests too ([#​1472](diffplug/spotless#1472)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
I found a bug with klint, especially the use of .editorconfig file.
When I use only klint the indend_size of the file is well use but not with spotless.
Is there a configuration to put in spotless?
Below my config:
build.gradle
spotless { kotlin { ktlint('0.9.2') } }
.editorconfig
The text was updated successfully, but these errors were encountered: