15

I'm a little confused about the differences of:

swiftlint:disable:next
swiftlint:disable:this
mfaani
  • 33,269
  • 19
  • 164
  • 293

1 Answers1

28

They're both used for disabling a swift rule for a single line. You can also enable a rule for a single line. From SwiftLint GitHub:

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.

For example:

// swiftlint:disable:next force_cast
let noWarning = NSNumber() as! Int
let hasWarning = NSNumber() as! Int
let noWarning2 = NSNumber() as! Int // swiftlint:disable:this force_cast
let noWarning3 = NSNumber() as! Int
// swiftlint:disable:previous force_cast

You can also just disable the rule til the end of the file.

// swiftlint:disable force_cast

The rules will be disabled until the end of the file or until the linter sees a matching enable comment:

so assuming you put it at the top of the file then the rule is disabled until it sees // swiftlint:enable force_cast

Or just disable each and every rule

// swiftlint:disable:all
mfaani
  • 33,269
  • 19
  • 164
  • 293