From 57788e8dd8fa83a96bd6d5ebd52d99688ba63e52 Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Tue, 9 Jul 2024 12:02:12 -0700 Subject: [PATCH] fix lint script --- scripts/lint.zsh | 87 ++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/scripts/lint.zsh b/scripts/lint.zsh index 4a6f077..a00dd54 100755 --- a/scripts/lint.zsh +++ b/scripts/lint.zsh @@ -9,67 +9,66 @@ # # Runs SwiftLint and checks for installation of correct version. +set -e +export PATH="$PATH:/opt/homebrew/bin" + if [[ "${GITHUB_ACTIONS}" ]]; then # ignore on GitHub Actions exit 0 fi -set -e -export PATH="$PATH:/opt/homebrew/bin" +LINK="https://github.com/realm/SwiftLint" +INSTALL="brew install swiftlint" + +if ! which swiftlint >/dev/null; then + echo " + Error: SwiftLint not installed! + + Download: $LINK + Install: $INSTALL + " + exit 0 +fi PROJECT="Foil.xcodeproj" SCHEME="Foil" VERSION="0.55.1" - FOUND=$(swiftlint version) -LINK="https://github.com/realm/SwiftLint" -INSTALL="brew install swiftlint" - CONFIG="./.swiftlint.yml" -if which swiftlint >/dev/null; then - echo "Running swiftlint..." +echo "Running swiftlint..." +echo "" + +# no arguments, just lint without fixing +if [[ $# -eq 0 ]]; then + swiftlint --config $CONFIG echo "" +fi - # no arguments, just lint without fixing - if [[ $# -eq 0 ]]; then - swiftlint --config $CONFIG +for argval in "$@" +do + # run --fix + if [[ "$argval" == "fix" ]]; then + echo "Auto-correcting lint errors..." + echo "" + swiftlint --fix --progress --config $CONFIG && swiftlint --config $CONFIG + echo "" + # run analyze + elif [[ "$argval" == "analyze" ]]; then + LOG="xcodebuild.log" + echo "Running anaylze..." + echo "" + xcodebuild -scheme $SCHEME -project $PROJECT clean build-for-testing > $LOG + swiftlint analyze --fix --progress --format --strict --config $CONFIG --compiler-log-path $LOG + rm $LOG + echo "" + else + echo "Error: invalid arguments." + echo "Usage: $0 [fix] [analyze]" echo "" fi - - for argval in "$@" - do - # run --fix - if [[ "$argval" == "fix" ]]; then - echo "Auto-correcting lint errors..." - echo "" - swiftlint --fix --progress --config $CONFIG && swiftlint --config $CONFIG - echo "" - # run analyze - elif [[ "$argval" == "analyze" ]]; then - LOG="xcodebuild.log" - echo "Running anaylze..." - echo "" - xcodebuild -scheme $SCHEME -project $PROJECT clean build-for-testing > $LOG - swiftlint analyze --fix --progress --format --strict --config $CONFIG --compiler-log-path $LOG - rm $LOG - echo "" - else - echo "Error: invalid arguments." - echo "Usage: $0 [fix] [analyze]" - echo "" - fi - done -else - echo " - Error: SwiftLint not installed! - - Download: $LINK - Install: $INSTALL - " - exit 0 -fi +done if [ $FOUND != $VERSION ]; then echo "