I'm a little confused about the differences of:
swiftlint:disable:next
swiftlint:disable:this
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>...]
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>...]
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With