New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

excluded should override SCRIPT_INPUT_FILE_* #591

Closed
demosdemon opened this Issue Mar 21, 2016 · 5 comments

Comments

Projects
None yet
6 participants
@demosdemon
Copy link

demosdemon commented Mar 21, 2016

The excluded config variable should override SCRIPT_INPUT_FILE_* environment. The frustrating framework situation for swift command line apps has me including the source of a module directly into my project and I don't want to lint it. ExtraBuildPhase puts it in the environment and swiftlint runs on it anyways ignoring my excluded rule.

@jpsim jpsim added the enhancement label Mar 21, 2016

@notjosh

This comment has been minimized.

Copy link

notjosh commented Feb 13, 2017

Not sure if you're using this in your precommit hooks, but that's the situation I'm in. Apologies if this isn't strictly relevant, but this issue came up when I searched.

For anyone trying to exclude values during a precommit hook like I was, here's the workaround I'm using until this issue is addressed. (It's based on the precommit hook template everyone seems to be using..not sure who to credit, but it wasn't me):

#!/bin/bash

SWIFT_LINT=Pods/SwiftLint/swiftlint
SWIFT_LINT_YAML=.swiftlint.yml

#           find 'excluded:' to next key/blank line               strip key     strip blank lines             strip array notation
EXCLUDED=($(sed -nE '/excluded:/,/(^$|:$)/p' ${SWIFT_LINT_YAML} | grep -v ':' | grep -v -e '^[[:space:]]*$' | sed -e 's/  - //g'))

contains () {
    local seeking=$1
    local in=1
    for element in "${EXCLUDED[@]}"; do
        if [ "$seeking" != "${seeking%$element*}" ]; then
            in=0
            break
        fi
    done
    return $in
}

if command -v ${SWIFT_LINT} >/dev/null 2>&1; then
    count=0
    for file_path in $(git ls-files -m --exclude-from=.gitignore | grep ".swift$"); do
        if contains $file_path; then
            continue
        fi
        export SCRIPT_INPUT_FILE_$count=$file_path
        count=$((count + 1))
    done

##### Check for modified files in unstaged/Staged area #####
    for file_path in $(git diff --name-only --cached | grep ".swift$"); do
        if contains $file_path; then
            continue
        fi
        export SCRIPT_INPUT_FILE_$count=$file_path
        count=$((count + 1))
    done

##### Make the count avilable as global variable #####
    export SCRIPT_INPUT_FILE_COUNT=$count

##### Lint files or exit if no files found for lintint #####
    if [ "$count" -ne 0 ]; then
        ${SWIFT_LINT} lint --use-script-input-files

        RESULT=$?

        if [ $RESULT -eq 0 ]; then
            echo "[SwiftLint] Violation found of the type WARNING! Consider fixing them before commit!"
        else
            echo "[SwiftLint] Violation found of the type ERROR! Must fix before commit!"
            exit $RESULT
        fi
    fi
else
    echo "warning: SwiftLint not installed, install via `pod install`"
fi

It's using some fragile-ish sed/grep commands to read the yaml file, and bash arrays are always scary, but it's working okay for me. Hope it helps someone else!

@b-ray

This comment has been minimized.

Copy link

b-ray commented Sep 19, 2017

Hi @demosdemon, I created a fork that should fix this problem some time ago.
If you want, you could give it a try, I just updated the changes to the latest SwiftLint version.
It's in my SwiftLint fork in the feature/filterScriptInputFiles branch: https://github.com/b-ray/SwiftLint/tree/feature/filterScriptInputFiles

@Johennes

This comment has been minimized.

Copy link

Johennes commented Sep 19, 2017

@b-ray Any chance to merge that back into the official version as a PR?

@lilyball

This comment has been minimized.

Copy link

lilyball commented May 2, 2018

Bump. This seems like a no-brainer and we shouldn't have to try to work around this.

@jpsim

This comment has been minimized.

Copy link
Collaborator

jpsim commented May 6, 2018

I agree this should be done. PR in progress is #1847.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment