Skip to content

Commit

Permalink
[gardening]: batch swiftlint calls for all modified files (#261)
Browse files Browse the repository at this point in the history
### Issue

the current pre-commit hook builds & runs swiftformat on every lint-able file, which can take a relatively long time if many changes have been made

### Description

- updates commit hook script to make one call to swiftformat with all the files to lint
- adds a `swiftversion` config specifying 5.7 as the language version the linter will use when running
jamieQ authored Jan 2, 2024
1 parent fb95bae commit 54d7ece
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read line; do
swift run swiftformat "${line}" --quiet;
git add "$line";
done

swift_files=$(git diff --diff-filter=d --staged --name-only -- '*.swift')

echo $swift_files | xargs swift run swiftformat --quiet

echo $swift_files | xargs git add
7 changes: 6 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
--indent 4
# file config

--swiftversion 5.7
--exclude Pods,Tooling,**Dummy.swift

# format config

--indent 4

--wraparguments before-first
--importgrouping testable-bottom

0 comments on commit 54d7ece

Please sign in to comment.