Skip to content

Commit

Permalink
[Swiftlint] Only lints changed&added files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfurrow committed Jun 28, 2016
1 parent 54584b6 commit 587dedd
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions config/setup_swiftlint_precommit_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@

PRECOMMIT_HOOK_FILENAME = '.git/hooks/pre-commit'
PRECOMMIT_HOOK = <<-EOS
# Modified from https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062
run_swiftlint() {
local filename="${1}"
if [[ "${filename##*.}" == "swift" ]]; then
# Tests and prod code have different configs, use the proper one.
if [[ $filename == Artsy_Tests* ]]; then
swiftlint lint --quiet --config Artsy_Tests/.swiftlint.yml --path "${filename}"
else
swiftlint lint --quiet --config Artsy/.swiftlint.yml --path "${filename}"
fi
fi
}
if which swiftlint >/dev/null; then
swiftlint lint --quiet --config Artsy/.swiftlint.yml
swiftlint lint --quiet --config Artsy_Tests/.swiftlint.yml
echo "SwiftLint version: $(swiftlint version)"
git diff --name-only | while read filename; do run_swiftlint "${filename}"; done
git diff --cached --name-only | while read filename; do run_swiftlint "${filename}"; done
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
EOS

def write_precommit_hook
Expand Down

0 comments on commit 587dedd

Please sign in to comment.