Hey. Thanks for the awesome tool
I want to enforce using SwiftLint and mark all SwiftLint warning as errors. Now I have to write:
line_length:
warning: 120
error: 120
Can I set some option like in Xcode treat warnings as errors for all SwiftLint warnings?
This can be achieved by using warning_threshold: 0 in your .yml file
Any way to treat only SwiftLint warnings as errors? warning_threshold: 0 will treat external warnings as errors as well.
So it seems that if you want to use the default rules (with some disabled possibly) you have to list every rule separately, e.g.
control_statement:
severity: error
to get them all to produce errors. I don't want to use xcode settings.
Did anybody try warning_threshold: 0? I have an Xcode build setting treat warnings as errors, so the build has no warnings/error, but the swiftlint fails. It works only if I set warning_threshold: 1.
Can I set some option like in Xcode
treat warnings as errorsfor all SwiftLint warnings?
Yes, that's the --strict option to the lint command:
$ swiftlint help lint
Print lint warnings and errors (default command)
...
[--strict]
fail on warnings
As an FYI for people discovering this thread, --strict does not convert warnings to errors, it changes the exit code for lints that only contains warnings to non-zero, which causes Xcode to say that the build phase failed, but doesn't change any of the warnings into errors.
It is possible to treat all swiftlint warnings as errors by modifying the swiftlint output like this:
#!/bin/bash
# Make the script return a failure code if any of the commands executed in the middle fail (even if they are piped)
# For more info, see: https://stackoverflow.com/questions/821396/aborting-a-shell-script-if-any-command-returns-a-non-zero-value
set -e
set -o pipefail
swiftlint lint --strict | sed 's/warning:/error:/g'
Or in case you are using swiftlint from cocoapods:
${PODS_ROOT}/SwiftLint/swiftlint lint --strict | sed 's/warning:/error:/g'
Did anybody try
warning_threshold: 0? I have an Xcode build settingtreat warnings as errors, so the build has no warnings/error, but the swiftlint fails. It works only if I setwarning_threshold: 1.
I ran into the same problem and opened an issue:
https://github.com/realm/SwiftLint/issues/2403
for those integrating SwiftLint via Cocoapods, update your SwiftLint build phase to run this script:
${PODS_ROOT}/SwiftLint/swiftlint --strict
Enough sed!
Most helpful comment
Yes, that's the
--strictoption to thelintcommand: