I'm trying to run SwiftLint on a Swift package. I have installed SwiftLint via mint. From the root of my project directory I can run mint run swiftlint, and this lints my project correctly.
As a next step, I would like this automated with the errors/warnings showing up in Xcode. I've tried
Editing Package.swift, and adding SwiftLint as a package dependency and a plugin on target. While this shows me the errors/warnings in Xcode, it does not process my .swiftlint.yml file.
Editing my scheme, and then adding a run script to my pre (have also tried post) build actions. While this runs the linting (and honors my .swiftlint.yml), it does not show the issues in Xcode. My script is
# Type a script or drag a script file from your workspace to insert its path.
export PATH="$PATH:/opt/homebrew/bin"
if mint which realm/swiftlint > /dev/null; then
cd "$WORKSPACE_PATH/../../.."
mint run realm/swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Hi, do you have your .swiftlint.yml file located in the root directory? It's mentioned in the SwiftLing README:
Due to limitations with Swift Package Manager Plug-ins this is only recommended for projects that have a SwiftLint configuration in their root directory as there is currently no way to pass any additional options to the SwiftLint executable.
There is no way how to display SwiftLint warnings or errors when you run a custom script in pre/post build actions. This is one of the reasons why build tools plugins were created.
For my project, I chose a different way to implement SwiftLint in my packages. I added the SwiftLint plugin dependencies in the dependency configuration as you can see in the example below.