SwiftLint is an app which helps facilitate automatically checking style in Swift. When set up properly with the Vokal style files, this app will give you warnings for various style inconsistencies.

SwiftLint is open source. Use is therefore strongly encouraged.

Note that the style files do not cover all of our code standards, since SwiftLint only covers certain formatting options. You and your code reviewer are still responsible for keeping an eye out for anything the app might have missed. It is, however, a great way to keep from getting "Hey, you missed a bracket on the wrong line" comments in code review.

Initial Setup

If nobody on your project has already set up SwiftLint, the steps to do so are pretty simple. Here are the steps:


Ignoring Specific Lines

There are multiple ways you can go about ignoring lines with SwiftLint. For instance, you can specify the rule you want to ignore in balanced swiftlint:disable and swiftlint:enable comments. In the example below the force_cast rule is being ignored:

//swiftlint:disable force_cast

//The code you want to ignore for the force_cast rule
let foo = NSNumber() as! Int

//swiftlint:enable force_cast

It's also possible to modify a disable or enable command by appending :previous , :this or :next for only applying the command to the previous, this (current) or next line respectively.

let foo = NSNumber() as! Int
// swiftlint:disable:previous force_cast
// swiftlint:disable:next force_cast
let foo = NSNumber() as! Int
let foo = NSNumber() as! Int // swiftlint:disable:this force_cast

More documentation is available at the SwiftLint site.

Vokal Limitations