@@ -8,48 +8,51 @@ cd "$repo_root"
88
99tabs_report=" $( mktemp) "
1010trailing_ws_report=" $( mktemp) "
11- trap ' rm -f "$tabs_report" "$trailing_ws_report"' EXIT
11+ target_files_list=" $( mktemp) "
12+ trap ' rm -f "$tabs_report" "$trailing_ws_report" "$target_files_list"' EXIT
1213
13- if command -v rg > /dev/null 2>&1 ; then
14- rg -n $' \t ' --glob ' *.swift' --glob ' !**/.git/**' --glob ' !**/.build/**' . > " $tabs_report " || true
15- if [[ -s " $tabs_report " ]]; then
16- head -n 50 " $tabs_report "
17- if [[ " $( wc -l < " $tabs_report " ) " -gt 50 ]]; then
18- echo " ...truncated (showing first 50 matches)"
14+ if [[ " $# " -gt 0 ]]; then
15+ for file in " $@ " ; do
16+ if [[ -f " $file " && " $file " == * .swift ]]; then
17+ echo " $file " >> " $target_files_list "
1918 fi
20- echo " Swift style check: tabs found in Swift files." >&2
21- errors=1
22- fi
19+ done
20+ else
21+ find . -type f -name ' *.swift' -not -path ' ./.git/*' -not -path ' ./.build/*' > " $target_files_list "
22+ fi
2323
24- rg -n " [[:blank:]]$ " --glob ' *.swift ' --glob ' !**/.git/** ' --glob ' !**/.build/** ' . > " $trailing_ws_report " || true
25- if [[ -s " $trailing_ws_report " ]] ; then
26- head -n 50 " $trailing_ws_report "
27- if [[ " $( wc -l < " $trailing_ws_report " ) " -gt 50 ]] ; then
28- echo " ...truncated (showing first 50 matches) "
29- fi
30- echo " Swift style check: trailing whitespace found in Swift files. " >&2
31- errors=1
24+ if [[ ! -s " $target_files_list " ]] ; then
25+ echo " No Swift files found for style check. "
26+ exit 0
27+ fi
28+
29+ while IFS= read -r file ; do
30+ if grep -n $' \t ' " $file " > /tmp/codex-style-tabs. $$ 2> /dev/null ; then
31+ sed " s#^# $file :# " /tmp/codex-style-tabs. $$ >> " $tabs_report "
3232 fi
33- else
34- grep -RIn --include=' *.swift' $' \t ' . > " $tabs_report " || true
35- if [[ -s " $tabs_report " ]]; then
36- head -n 50 " $tabs_report "
37- if [[ " $( wc -l < " $tabs_report " ) " -gt 50 ]]; then
38- echo " ...truncated (showing first 50 matches)"
39- fi
40- echo " Swift style check: tabs found in Swift files." >&2
41- errors=1
33+ if grep -n -E " [[:blank:]]$" " $file " > /tmp/codex-style-trailing.$$ 2> /dev/null; then
34+ sed " s#^#$file :#" /tmp/codex-style-trailing.$$ >> " $trailing_ws_report "
4235 fi
36+ done < " $target_files_list "
4337
44- grep -RIn --include=' *.swift' -E " [[:blank:]]$" . > " $trailing_ws_report " || true
45- if [[ -s " $trailing_ws_report " ]]; then
46- head -n 50 " $trailing_ws_report "
47- if [[ " $( wc -l < " $trailing_ws_report " ) " -gt 50 ]]; then
48- echo " ...truncated (showing first 50 matches)"
49- fi
50- echo " Swift style check: trailing whitespace found in Swift files." >&2
51- errors=1
38+ rm -f /tmp/codex-style-tabs.$$ /tmp/codex-style-trailing.$$
39+
40+ if [[ -s " $tabs_report " ]]; then
41+ head -n 50 " $tabs_report "
42+ if [[ " $( wc -l < " $tabs_report " ) " -gt 50 ]]; then
43+ echo " ...truncated (showing first 50 matches)"
5244 fi
45+ echo " Swift style check: tabs found in Swift files." >&2
46+ errors=1
47+ fi
48+
49+ if [[ -s " $trailing_ws_report " ]]; then
50+ head -n 50 " $trailing_ws_report "
51+ if [[ " $( wc -l < " $trailing_ws_report " ) " -gt 50 ]]; then
52+ echo " ...truncated (showing first 50 matches)"
53+ fi
54+ echo " Swift style check: trailing whitespace found in Swift files." >&2
55+ errors=1
5356fi
5457
5558swift_format_cmd=" "
@@ -60,10 +63,12 @@ elif xcrun --find swift-format >/dev/null 2>&1; then
6063fi
6164
6265if [[ -n " $swift_format_cmd " && -f " $repo_root /.swift-format" ]]; then
63- if ! eval " $swift_format_cmd lint --recursive ." ; then
64- echo " Swift style check: swift-format lint failed." >&2
65- errors=1
66- fi
66+ while IFS= read -r file; do
67+ if ! eval " $swift_format_cmd lint \" $file \" " ; then
68+ echo " Swift style check: swift-format lint failed for $file ." >&2
69+ errors=1
70+ fi
71+ done < " $target_files_list "
6772else
6873 echo " swift-format lint skipped (missing swift-format command or .swift-format config)."
6974fi
0 commit comments