kotlinter-gradle
kotlinter-gradle copied to clipboard
How to run formatKotlin on a specific file/files?
Hi, I'm wondering if it possible to run
./gradlew formatKotlin -Pfiles = {path to file}
or something like that.
Thanks.
I can think of:
tasks.register("sampleTask", org.jmailen.gradle.kotlinter.tasks.FormatTask) {
source project.property("files")
}
which would allow you to call ./gradlew sampleTask -Pfiles={path relative to project directory}
Can you describe your use case?
Yeh, use very similar solution in our project. That's only for the formatting in the pre commit hook.
#!/bin/sh
set -e
echo 1>&2 "running formatKotlin"
filesToFormat="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.kts|\.kt/ { print $2}')"
echo "files to format $filesToFormat"
for sourceFilePath in $filesToFormat
do
./gradlew formatKotlinFile -Pfile="$(pwd)/$sourceFilePath"
git add "$sourceFilePath"
done;
I know it wont work perfect for the partial commit, but it's fine for us now.
Hope you'll adjust your own pre commit hooks and I switch on it.
We have exactly the same use case. Any updates or workarounds on this specific use case so far?