Skip to content

Instantly share code, notes, and snippets.

@alexmx
Created August 21, 2018 18:54
Show Gist options
  • Save alexmx/e7647976fdb616c54c42042b83d86a0b to your computer and use it in GitHub Desktop.
Save alexmx/e7647976fdb616c54c42042b83d86a0b to your computer and use it in GitHub Desktop.
Run SwiftLint against files which have been changed in the current branch relative to RELATIVE_BRANCH (eg. master)
#!/bin/bash
# Path to the repository root folder
REPO_ROOT_DIR=$1
# The branch name relative to which the modified files will be determined
RELATIVE_BRANCH=$2
# The path to the SwiftLint command.
SWIFT_LINT_PATH=$3
run_swiftlint() {
local filename="${1}"
if [[ "${filename##*.}" == "swift" ]]; then
$SWIFT_LINT_PATH lint --path "${filename}" --lenient
fi
}
run_swiftlint_modified_files() {
# Run SwiftLint against files which have been changed in the current branch relative to RELATIVE_BRANCH
git diff $RELATIVE_BRANCH --name-only | while read filename; do run_swiftlint "${filename}"; done
}
pushd $REPO_ROOT_DIR
run_swiftlint_modified_files
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment