my question is very simple, how do I make all warnings
become errors
on SwiftLint? (without manually configuring each rule separately)

- 37,241
- 25
- 195
- 267

- 4,248
- 6
- 43
- 75
-
Try the `--strict` option – Andrew Li Feb 23 '17 at 04:09
-
Where do I add this `--strict` ? – Rodrigo Ruiz Mar 04 '17 at 21:29
-
1`"${PODS_ROOT}/SwiftLint/swiftlint" lint --strict` (for pod install) or `swiftlint lint --strict` (for brew install) – Cœur Mar 30 '17 at 01:46
3 Answers
To integrate SwiftLint to your project, you normally need to add a Run Script Phase, as described by the doc.
If you used the CocoaPods installation, this script would look like:
"${PODS_ROOT}/SwiftLint/swiftlint"
That is where you can customize the command line options. In your case, you may want to use:
"${PODS_ROOT}/SwiftLint/swiftlint" lint --strict
The warnings will still be displayed as warnings, but an extra error will be given, preventing running or archiving:
Command /bin/sh failed with exit code 3
That is the desired error.

- 37,241
- 25
- 195
- 267
-
Still get the error `/Pods/SwiftLint/swiftlint lint --strict: No such file or directory`. And the actual thing written in the script is `"${PODS_ROOT}/SwiftLint/swiftlint lint --strict"`, not `${PODS_ROOT}/SwiftLint/swiftlint lint --strict` – Rodrigo Ruiz Mar 30 '17 at 01:01
-
Their documentation shows the quotes https://github.com/realm/SwiftLint like I wrote. And yes, I am using CocoaPods. – Rodrigo Ruiz Mar 30 '17 at 01:46
-
And even if I remove the quotes, I get this error `Command /bin/sh failed with exit code 3` – Rodrigo Ruiz Mar 30 '17 at 01:47
-
It's not showing me the line where the error is, the warnings are still warnings. – Rodrigo Ruiz Mar 30 '17 at 01:49
-
Is there a way to be a little better and have the warnings display as errors? But in any case, thank you for the help. – Rodrigo Ruiz Mar 30 '17 at 01:50
-
That's how it's supposed to be. It's explained in the post, and that's best you can have. – Cœur Mar 30 '17 at 01:50
-
This answer helped me on passing external config to SwiftLint by Cocoapods in this way `"${PODS_ROOT}/SwiftLint/swiftlint" lint --config "${PROJECT_DIR}/.swiftlint.yml"` – BuguiBu Mar 14 '19 at 13:28
-
@buguibu I don't think you need to explicitly set the path to a .swiftlint.yml when it's already in your project root folder. – Cœur Mar 14 '19 at 15:19
-
@Cœur i've tried that way without success, did you? I guess it's needed, if the Pod contains just the swiftlint command and if it,s like the command installed by homebrew it doesn,t looks for configuration file in any path by default. – BuguiBu Mar 15 '19 at 07:44
-
@buguibu two of my pods have .swiftlint.yml in the root folder: [here](https://github.com/Coeur/ImageEffects/blob/master/Example/.swiftlint.yml) and [here](https://github.com/Coeur/CollectionViewCenteredFlowLayout/blob/master/Example/.swiftlint.yml), and when you look at their respective script [here](https://github.com/Coeur/ImageEffects/blob/master/Example/SwiftImageEffects.xcodeproj/project.pbxproj#L333) and [here](https://github.com/Coeur/CollectionViewCenteredFlowLayout/blob/master/Example/CollectionViewCenteredFlowLayout.xcodeproj/project.pbxproj#L264) they don't need any config path. – Cœur Mar 15 '19 at 09:38
-
@Cœur and do you have SwiftLint installed by Homebrew or just the Pod? – BuguiBu Mar 15 '19 at 10:09
-
@buguibu just the pod: 1. the script is `shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\"\n";` 2. there is a .travis file in the repo to run the tests, and travis doesn't have SwiftLint by default – Cœur Mar 15 '19 at 13:40
One drawback with "--strict" flag is that it won't show which line has a Warning.
You can pipe the output and replace "warning" with "error" by adding:
| sed "s/warning:/error:/"
the whole command will look like:
"${PODS_ROOT}/SwiftLint/swiftlint" lint --strict | sed "s/warning:/error:/"
then Xcode will show all SwiftLint warnings as errors.

- 193
- 1
- 8
You can make every swiftlint rule throw an error by enabling --strict
swiftlint lint --strict
Alternatively, you can configure each rule of swiftlint if you are using a config.yml
file so that only certain rules throw an error.
swiftlint lint --config 'config.yml'
In the config.yml
file simply add the configuration for the rule you want to throw as an error.
implicit_return:
severity: error
I believe this will work for any swiftlint rule. This is useful if you are looking to gradually adopt a stricter approach to linting.

- 13
- 4