`swift-format` linting with Xcode

I have a custom run script phase to lint my app target with swift format:

swift-format lint -r ${PROJECT_DIR}

Without specifying input files of the phase I'm getting "Sandbox: swift-format(53037) deny(1) file-read-data .../Folder/file1.swift", so I have to specify input files, and after that swift-format linting works great... although it requires me to either list each and every swift file in the "Input Files" of the phase, or (almost equally painful) list them all in the .xcfilelist file:

$(SRCROOT)/Folder/file1.swift
$(SRCROOT)/Folder/file2.swift
... and so on

I can't specify a folder in there. Tried $(SRCROOT)/Folder", $(SRCROOT)/Folder/", $(SRCROOT)/Folder/*.swift", etc - nothing like this works.

Is that how swift-format linting suppose to work or am I missing something?

I can't be the first one to solve this, or am I ?!

Simplest solution is to turn off the build script sandbox. Otherwise Xcode's build scripts aren't flexible enough to do what we need here. It should be possible for Xcode to give scripts the list of changed files, or even all files, and to designate which build steps it should run before or after, but those improvements seem unlikely.

2 Likes