Skip to content

Instantly share code, notes, and snippets.

@tahirmt
Forked from teameh/swiftlint.sh
Created March 2, 2023 23:20
Show Gist options
  • Select an option

  • Save tahirmt/7f2aba3ec7c482c181d1673b64e5ddb5 to your computer and use it in GitHub Desktop.

Select an option

Save tahirmt/7f2aba3ec7c482c181d1673b64e5ddb5 to your computer and use it in GitHub Desktop.

Revisions

  1. @teameh teameh revised this gist May 8, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions swiftlint.sh
    Original file line number Diff line number Diff line change
    @@ -21,16 +21,16 @@ if [[ $* == *--all* ]]; then
    exit 0
    fi

    # make for .. in work with the shitty spaces in our filenames
    OIFS="$IFS"
    IFS=$'\n'

    # Always lint AppDelegate to prevent "No lintable files found at paths: ''"
    # caused by a combination --use-script-input-files and --force-exclude
    # See https://github.com/realm/SwiftLint/issues/2619
    export SCRIPT_INPUT_FILE_0="Sources/AppDelegate.swift"
    count=1

    # make for .. in work with the shitty spaces in our filenames
    OIFS="$IFS"
    IFS=$'\n'

    # Changed files not added to stage area yet
    for file_path in $(git diff --diff-filter=d --name-only | grep ".swift$"); do
    export SCRIPT_INPUT_FILE_$count=$file_path
  2. @teameh teameh created this gist May 8, 2019.
    60 changes: 60 additions & 0 deletions swiftlint.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #!/bin/bash
    set -e

    if [ "$CI" == true ]; then
    echo "CI == true, skipping this script"
    exit 0
    fi

    SWIFT_LINT=./Pods/SwiftLint/swiftlint

    if ! [[ -e "${SWIFT_LINT}" ]]; then
    echo "${SWIFT_LINT} is not installed."
    exit 0
    fi

    echo "SwiftLint $(${SWIFT_LINT} version)"

    if [[ $* == *--all* ]]; then
    ${SWIFT_LINT} autocorrect
    ${SWIFT_LINT} lint
    exit 0
    fi

    # make for .. in work with the shitty spaces in our filenames
    OIFS="$IFS"
    IFS=$'\n'

    # Always lint AppDelegate to prevent "No lintable files found at paths: ''"
    # caused by a combination --use-script-input-files and --force-exclude
    # See https://github.com/realm/SwiftLint/issues/2619
    export SCRIPT_INPUT_FILE_0="Sources/AppDelegate.swift"
    count=1

    # Changed files not added to stage area yet
    for file_path in $(git diff --diff-filter=d --name-only | grep ".swift$"); do
    export SCRIPT_INPUT_FILE_$count=$file_path
    count=$((count + 1))
    done

    # Changed files added to stage area
    for file_path in $(git diff --diff-filter=d --name-only --cached | grep ".swift$"); do
    export SCRIPT_INPUT_FILE_$count=$file_path
    count=$((count + 1))
    done

    # Newly added untracked files
    for file_path in $(git ls-files --others --exclude-standard | grep ".swift$"); do
    export SCRIPT_INPUT_FILE_$count=$file_path
    count=$((count + 1))
    done


    if [ "$count" -ne 0 ]; then
    export SCRIPT_INPUT_FILE_COUNT=$count
    $SWIFT_LINT autocorrect --use-script-input-files --force-exclude
    $SWIFT_LINT lint --use-script-input-files --force-exclude
    else
    echo "No files to lint!"
    exit 0
    fi