Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force error on SwiftLint instead of warnings?

Tags:

swiftlint

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

like image 772
Rodrigo Ruiz Avatar asked Feb 23 '17 04:02

Rodrigo Ruiz


2 Answers

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.

like image 123
Grand M Avatar answered Nov 16 '22 15:11

Grand M


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.

like image 42
Cœur Avatar answered Nov 16 '22 14:11

Cœur