-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast-format
More file actions
executable file
·46 lines (35 loc) · 1.2 KB
/
fast-format
File metadata and controls
executable file
·46 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
set -euo pipefail
echo "Script started with $# arguments"
echo "Arguments: $*"
echo "Script location: $(dirname "$0")"
cd "$(dirname "$0")/.."
echo "Changed to directory: $(pwd)"
if [ $# -eq 0 ]; then
echo "Usage: $0 <file-with-paths> [additional-formatter-args...]"
echo "The file should contain one file path per line"
exit 1
fi
FILE_LIST="$1"
echo "Looking for file: $FILE_LIST"
if [ ! -f "$FILE_LIST" ]; then
echo "Error: File '$FILE_LIST' not found"
exit 1
fi
if ! command -v ktfmt &> /dev/null; then
echo "Error: ktfmt not found"
exit 1
fi
# Process Kotlin files
echo "==> Looking for Kotlin files"
kt_files=$(grep -E '\.kt$' "$FILE_LIST" | grep -v './buildSrc/build/' || true)
echo "==> Done looking for Kotlin files"
if [[ -n "$kt_files" ]]; then
echo "==> will format Kotlin files"
echo "$kt_files" | tr '\n' '\0' | xargs -0 ktfmt --kotlinlang-style "$@"
else
echo "No Kotlin files to format -- expected outcome during incremental formatting"
fi
# TODO(mbudayr): support palantir-java-format
# Process Java files
# grep -E '\.java$' "$FILE_LIST" | grep -v './buildSrc/build/' | tr '\n' '\0' | xargs -0 -r palantir-java-format --palantir --replace "$@"