Skip to content

Commit

Permalink
Add Swiftlint to bit pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Nov 7, 2023
1 parent f5973b9 commit 5bb573a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

ROOT_DIR=$(pwd)/../../

cp pre-commit ../.git/hooks

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Expand Down
17 changes: 17 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# Redirect output to stderr.
exec 1>&2

# Stash any unstaged changes
git stash -q --keep-index

# Run SwiftLint only on staged files
git diff --cached --name-only --diff-filter=ACM | grep "\.swift$" | while read file; do
swiftlint --fix --format "$file" 2>/dev/null
done

# Stash the unstaged changes that were stashed previously
git stash pop -q

exit 0

0 comments on commit 5bb573a

Please sign in to comment.