Skip to content

Instantly share code, notes, and snippets.

@nanoxd
Created November 11, 2018 14:27
Show Gist options
  • Save nanoxd/d9d63caa9c95eb8292ed8273a0bd314e to your computer and use it in GitHub Desktop.
Save nanoxd/d9d63caa9c95eb8292ed8273a0bd314e to your computer and use it in GitHub Desktop.
[bin/lint] Binary to run swiftlint, meant to be placed at the root of the project #sh
#!/bin/sh
#
# Lint any changed files using swiftlint.
#
# This works both independently and as a run phase script.
# Path to installed version of Swift lint.
readonly SWIFT_LINT_PATH=$(which swiftlint)
if [ -z "$SWIFT_LINT_PATH" ]; then
echo "warning: SwiftLint not installed. Run 'brew bundle' to ensure its installation."
exit 0
fi
_lint() {
local filename="${1}"
if [[ "${filename##*.}" == "swift" ]]; then
${SWIFT_LINT_PATH} lint --path "${filename}"
fi
}
git diff --cached --name-only | while read filename; do _lint "${filename}"; done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment