Rodrigo Ruiz
Rodrigo Ruiz

Reputation: 4355

How to force error on SwiftLint instead of warnings?

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

Upvotes: 17

Views: 11574

Answers (3)

richardjsimkins
richardjsimkins

Reputation: 13

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.

Upvotes: 1

Grand M
Grand M

Reputation: 312

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.

Upvotes: 10

Cœur
Cœur

Reputation: 38667

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.

Upvotes: 18

Related Questions