Skip to content
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

How to skip the unmodified swift files #1343

Closed
snice opened this issue Mar 7, 2017 · 5 comments
Closed

How to skip the unmodified swift files #1343

snice opened this issue Mar 7, 2017 · 5 comments
Labels

Comments

@snice
Copy link

snice commented Mar 7, 2017

I have 100+ files, run cmd,
swiftlint autocorrect --format

but, Every time is slow。I want to hurry up, how to do?
For example, filter for modified files. Thanks..

@mgrebenets
Copy link
Contributor

This isn't really SwiftLint feature.
Are you using git?

This is an example of shell script we have integrated as part of our Xcode project

#!/bin/bash

# Run SwiftLint
START_DATE=$(date +"%s")

SWIFT_LINT=/usr/local/bin/swiftlint

# Run SwiftLint for given filename
run_swiftlint() {
    local filename="${1}"
    # Ignore Pods/ paths
    [[ "${filename}" =~ Pods/ ]] && return
    if [[ "${filename##*.}" == "swift" ]]; then
        ${SWIFT_LINT} autocorrect --path "${filename}"
        ${SWIFT_LINT} lint --path "${filename}"
    fi
}

if [[ -e "${SWIFT_LINT}" ]]; then
    echo "SwiftLint version: $(${SWIFT_LINT} version)"
    # Run for both staged and unstaged files
    git diff --name-only | while read -r filename; do run_swiftlint "${filename}"; done
    git diff --cached --name-only | while read -r filename; do run_swiftlint "${filename}"; done
else
    echo "Error: ${SWIFT_LINT} is not installed."
    exit 1
fi

END_DATE=$(date +"%s")

DIFF=$((END_DATE - START_DATE))
echo "SwiftLint took $((DIFF / 60)) minutes and $((DIFF % 60)) seconds to complete."

@marcelofabri
Copy link
Collaborator

@snice Did @mgrebenets's comment solve your issue?

@jpsim
Copy link
Collaborator

jpsim commented Mar 10, 2017

I'd like to state that with SwiftLint's caching (minus current bugs we're dealing with), only modified files should be re-linted.

@mgrebenets
Copy link
Contributor

@jpsim That means "modified" in the SwiftTerms terms, right?

For our team it was important to use the git's meaning of "modified" and only lint the files which developer has touched, since there's no mechanism to share same cache between multiple developers.

For CI builds we lint the whole project - this is where cache becomes more important for us.

@jpsim
Copy link
Collaborator

jpsim commented Mar 21, 2017

What's "SwiftTerms terms"? By modified I mean different since the last run persisted in the cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants