lassik / emacs-format-all-the-code

Auto-format source code in many languages with one command
https://melpa.org/#/format-all
MIT License
604 stars 105 forks source link

Question: Ktlint formatter messes up formatting build.gradle.kts files? #237

Closed torgeir closed 11 months ago

torgeir commented 1 year ago

Hi,

Thanks for a great package! I enjoy this every day as part of doom emacs.

The ktlint formatter seems to mess up formatting build.gradle.kts on my end, so I am writing here just to confirm if this is an issue for you too.

E.g. file

// build.gradle.kts
dependencies {
}

After formatting

20:45:25.882 [main] INFO com.pinterest.ktlint.cli.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
20:45:26.506 [main] WARN com.pinterest.ktlint.cli.internal.KtlintCommandLine - Can not parse input from <stdin> as Kotlin, due to error below:
    Not a valid Kotlin file (1:1 expecting a top level declaration)
Now, trying to read the input as Kotlin Script.
dependencies {
}

I have fixed this temporarily by preventing log output other than for error messages by the following.

(define-format-all-formatter ktlint
    (:executable "ktlint")
    (:install (macos "brew install ktlint"))
    (:modes kotlin-mode)
    (:format (format-all--buffer-easy executable "--format" "-l" "error" "--stdin")))

This seems like more of an issue with ktlint than with this module per se, I just wanted to check if this is also how it fares on your end.

Best regards, Torgeir

lassik commented 11 months ago

PR #213 is a workaround for this issue. Let's apply it until the upstream issue is fixed.

torgeir commented 11 months ago

Agreed. An upstream fix feels like the right thing.