swiftswiftlint

What's the difference between swiftlint:disable:next and swiftlint:disable:this?


I'm a little confused about the differences of:

swiftlint:disable:next
swiftlint:disable:this

Solution

  • 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. Note: for all there is a space used as opposed to :

    // swiftlint:disable all