-
-
Notifications
You must be signed in to change notification settings - Fork 71
Add support for ktlint fix
with -F
#224
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
base: main
Are you sure you want to change the base?
Add support for ktlint fix
with -F
#224
Conversation
ktlint fix
with -F
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ktlint
support 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-run
thathello.kt
would be updated