
đ The best productive Swiftlint stack with a baseline system
Swiftlint has been around for almost 9 years but still doesnât support the baseline feature. At Shopmium, here is the best workaround strategy we pushed in order to fix this lack of a significant feature when we are working on a Swift project with a large legacy codebase and we want to add Swiftlint to prevent writing code smells. đ Check out my article that list the 4 bests tools to integrate in your iOS githooks including Swiftlint
A baseline is a âfixedâ configuration of a project at a given moment.
What is the baseline by the way ?
A baseline is a âfixedâ configuration of a project at a given moment. Basically, in our case, a file could contain all different warnings of the whole project, and when Swiftlint runs, it will first look at this file. If a warning is already present in the âbaselineâ, it wonât raise a warning; it will be âmutedâ. Powerful baselines (such as Detekt or Ktlint) system allow the linter to unmute a warning if a single piece of the line saved has changed. This feature may pop in one day a PR is currently opened.
Swiftlint doesnât have a baseline feature, and in the 8-year-old project, we integrated and faced more than 6.5k warnings đš, but without a baseline, we could not spend time on it. Here are the four parts of the strategy we adopted (which could also be applied outside of a context of dealing with the lack of baseline).
- Step 0: Choose wisely your linter rules
- Step 1: Setup Swiftlint on Xcode
- Step 2: Setup Swiflint in the pre-commit githook
- Step 3: Swiftlint Danger plugin on CI Side

Step 0: Choose wisely your linter rules
We deactivated some rules that could be complicated to maintain without risking breaking the code behavior, and we couldnât check and add a //swiftlint:disable:next everywhere. So, we analyzed and removed some rules by commenting them with a comment: #To reenable with a baseline. We reduced 3k warnings with that.
Use the standalone tool instead of the SPM. Itâs more reusable and faster. No need to download it after a clean of the DerivedData
Step 1: Setup Swiftlint on Xcode
First of all, I recommend installing SwiftLint outside of Xcode. By installing it as a command-line tool instead of using the SPM package or CocoaPods, you can avoid downloading it every time after cleaning derivedData or when opening Xcode.
brew install swiftlint #as simple as this :D
The first hack is to not run SwiftLint on all files but only on unstaged and staged files in Git. This way, you wonât have warnings on files youâre not currently working on. If the file is a legacy one and long, it may present a challenge, but itâs also an opportunity to add some âswiftlint:disable:nextâ directives if you canât fix it immediately (with a strategy to address them later đȘ). Here is the script I implemented in my build phase.






