I’ve noticed that the SwiftLint plugin can add up to 30 seconds to incremental build times. In my case, it nearly doubled the average incremental build time!
Since there’s no straightforward way to disable SwiftLint across all local packages in a project, I decided on the simplest solution: automating the process of temporarily commenting out SwiftLint from the dependencies list.
In my projects, to ensure the SwiftLint plugin is automatically added to all package targets, I append the following code to each Swift package manifest:
// Inject base plugins into each target
package.targets = package.targets.map { target in
var plugins = target.plugins ?? []
plugins.append(.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins"))
target.plugins = plugins
return target
}
Here’s the shell script I use to comment out SwiftLint across all packages and create a temporary commit. You can add this to your shell configuration file:
Make sure your git working tree is clean before running this script. Otherwise, it will include your existing changes in the commit.
# .zshrc
# Disable SwiftLint
dsl() {
find . \( -path '*/.*' -prune \) -o -type f -name "Package.swift" -print | while read -r file; do
sed -i '' 's|plugins.append(.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins"))|//plugins.append(.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins"))|' "$file" && \
echo "Updated: $file"
done
git add -A && git commit -m "temp: disable swiftlint"
}