Skip to content

Commit edb9343

Browse files
chore: improve formatter performance
1 parent 7fec339 commit edb9343

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

scripts/fast-format

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
cd "$(dirname "$0")/.."
6+
7+
if [ $# -eq 0 ]; then
8+
echo "Usage: $0 <file-with-paths> [additional-formatter-args...]"
9+
echo "The file should contain one file path per line"
10+
exit 1
11+
fi
12+
13+
FILE_LIST="$1"
14+
15+
if [ ! -f "$FILE_LIST" ]; then
16+
echo "Error: File '$FILE_LIST' not found"
17+
exit 1
18+
fi
19+
20+
if command -v ktfmt-fast-format &> /dev/null; then
21+
echo "Error: ktfmt-fast-format not found"
22+
exit 1
23+
fi
24+
25+
# Process Kotlin files
26+
kt_files=$(grep -E '\.kt$' "$FILE_LIST" | grep -v './buildSrc/build/')
27+
kt_files=$(grep -E '\.kt$' "$FILE_LIST" | grep -v './buildSrc/build/')
28+
echo "==> Found $(echo "$kt_files" | wc -l) Kotlin files:"
29+
30+
if [[ -n "$kt_files" ]]; then
31+
echo "==> will format Kotlin files"
32+
echo "$kt_files" | tr '\n' '\0' | xargs -0 ktfmt --kotlinlang-style "$@"
33+
else
34+
echo "No Kotlin files to format -- expected outcome during incremental formatting"
35+
fi
36+
37+
# TODO(mbudayr): support palantir-java-format
38+
# Process Java files
39+
# grep -E '\.java$' "$FILE_LIST" | grep -v './buildSrc/build/' | tr '\n' '\0' | xargs -0 -r palantir-java-format --palantir --replace "$@"

0 commit comments

Comments
 (0)