7

I am working on an iOS Swift project. Git is being used for version controlling. I want to run swiftlint tool only for newly changed files. On other words, I want to check static issues only for the files that have been edited till last commit. If possible, I will add the script in Build phase -> Run script, so that every developer can find the static issues only for the files they are working on. Is it possible?

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256

2 Answers2

18

Adding this below command in Build phase - run script will be helpful.

Below code will work for staged files

git diff --cached --name-only | grep "\.swift" | while read filename; do
    swiftlint lint --path "$filename";
done

For unstaged files you need to remove --cached argument

git diff --name-only | grep "\.swift" | while read filename; do
    swiftlint lint --path "$filename";
done
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
0

You don't have to iterate through the items:

swiftlint lint --path $(git diff HEAD --name-only | grep "\.swift")

Also, git diff HEAD gives you staged and unstaged files.

pleshis
  • 406
  • 5
  • 7