Add support for ktlint fix with -F#224
Add support for ktlint fix with -F#224smocherla-brex wants to merge 3 commits intoaspect-build:mainfrom
ktlint fix with -F#224Conversation
ktlint fix with -F
alexeagle
left a comment
There was a problem hiding this comment.
This is confusing, they've shipped a format feature in the lint tool. We already have ktfmt in this repo. Is a user meant to choose one or the other?
|
|
|
I don't want to close the PR - we DO want to have auto-fixes for linters that understand them. I think we should raise a discussion on the ktlint repo to see if there's any recommended solution (and not make it Bazel specific - we just want to follow what other users do) |
|
I recently enabled both After running Runtime.getRuntime()
.addShutdownHook(
Thread {
println("Shutting down gRPC server...")
stop()
println("Server shut down.")
} // <-- no trailing comma
)After running Runtime.getRuntime()
.addShutdownHook(
Thread {
println("Shutting down gRPC server...")
stop()
println("Server shut down.")
}, // <-- trailing comma required here in order to satisfy linter
)I assume I can configure In fact, the trailing comma issue is the second conflict I hit. The first conflict I hit was with I don't know what other landmines I might hit as my project grows. Ultimately, I think |
FWIW, I was finally able to get both tools to not trample each other. In case it's useful for others who are struggling with this, here's what I did.
java_binary(
name = "ktfmt",
args = [
"--kotlinlang-style",
],
main_class = "com.facebook.ktfmt.cli.Main",
runtime_deps = [
"@maven//:com_facebook_ktfmt",
],
)
sh_binary(
name = "ktfmt_wrapper",
srcs = ["ktfmt.sh"],
data = [
":ktfmt",
"@bazel_tools//tools/jdk:current_java_runtime",
],
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
)
format_multirun(
# ...
kotlin = ":ktfmt_wrapper"
)The #!/usr/bin/env bash
$(dirname $0)/ktfmt --kotlinlang-style "$@"
For my current code, this seems to keep both tools happy. |
|
|
This is a follow-up to
ktlintsupport with an action to patch/autocorrect violations where supported in rules using https://pinterest.github.io/ktlint/1.0.1/install/cli/#format-autocorrect and leveraging existing semantics with rules_lintChanges are visible to end-users: yes
Test plan
./lint.sh --fix --dry-runthathello.ktwould be updated