Created
March 31, 2021 07:54
-
-
Save msewell/9a5219197c6500a4db4a2d59505bc81e to your computer and use it in GitHub Desktop.
Running SwiftLint as an Xcode behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -l | |
exec > /tmp/lintbehaviorlog-$(date "+%s").txt | |
exec 2>&1 | |
set -x # Call this command at the top of your script and every following command will be echoed. You can turn it off with set +x | |
set -e # abort the script when any command exits with non-zero status | |
OIFS="$IFS" | |
IFS=$'\n' | |
PROJECT_OR_WORKSPACE="${XcodeProjectPath:-$XcodeWorkspacePath}" | |
cd $(dirname $PROJECT_OR_WORKSPACE) | |
count=0 | |
for file in $(git diff --diff-filter=d --line-prefix=`git rev-parse --show-toplevel`/ --name-only | rg -i '.swift'); do | |
export SCRIPT_INPUT_FILE_$count="${file}" | |
count=$((count + 1)) | |
done | |
export SCRIPT_INPUT_FILE_COUNT=$count | |
if [ "$count" -ne 0 ]; then | |
swiftlint autocorrect --use-script-input-files --config ~/Developer/.swiftlint.yml > $(dirname $PROJECT_OR_WORKSPACE)/lint_autocorrections.txt | |
# FILE=$(dirname $PROJECT_OR_WORKSPACE)/lint_autocorrections.txt | |
# if [ -s ${FILE} ] | |
# then | |
# open ${FILE} | |
# fi | |
# swiftlint lint --use-script-input-files --config ~/Developer/.swiftlint.yml | fold -w180 > $(dirname $PROJECT_OR_WORKSPACE)/lint_behavior_violations.txt | |
swiftlint lint --use-script-input-files --config ~/Developer/.swiftlint.yml > $(dirname $PROJECT_OR_WORKSPACE)/lint_behavior_violations.txt | |
# FILE=$(dirname $PROJECT_OR_WORKSPACE)/lint_behavior_violations.txt | |
# if [ -s ${FILE} ] | |
# then | |
# open ${FILE} | |
# fi | |
fi | |
IFS="$OIFS" | |
set +x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment