Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 436
mfaani Avatar asked Apr 15 '20 21:04

mfaani


People also ask

How to disable rule in SwiftLint?

Disable rules in code Rules can be disabled with a comment inside a source file with the following format: // swiftlint:disable <rule1> [<rule2> <rule3>...] The rules will be disabled until the end of the file or until the linter sees a matching enable comment: // swiftlint:enable <rule1> [<rule2> <rule3>...]

How to disable SwiftLint for a file?

Option 2: Disable Rules at Source Level: Sometimes, there will be a case, where you want to disable rule(s) for a specific file or block of code. To disabled rules inside a source file use the following format: // swiftlint:disable <rule1> [<rule2> <rule3>...]

How does SwiftLint work?

SwiftLint is an open-source tool to enforce Swift style and conventions. It is developed by Realm. You can set your coding style rules and force them during development. SwiftLint has a command-line tool, Xcode plugin, AppCode, and Atom integration.

How do I see Swiftlint rules?

To see violated rules run the swiftlint lint by command line in your project directory. At the end of each warning, rule identifier is written inside the parentheses (`redundant_void_return` in the example), copy them somewhere until you find all of them.


1 Answers

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 for the entire 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 the entire file or until it sees // swiftlint:enable force_cast

Or just disable each and every rule

// swiftlint:disable:all
like image 75
mfaani Avatar answered Oct 17 '22 00:10

mfaani