Swiftlint: Rule Request: Flag `assert(false, …)` and `precondition(false, …)`

Created on 10 Jul 2018  Â·  2Comments  Â·  Source: realm/SwiftLint

New Issue Checklist

Rule Request

My coworkers keep adding code like

if (someCondition) {
    assert(false, "Error message goes here")
}

While this is necessary in Obj-C, in Swift we should be using asssertionFailure("Error message") (and preconditionFailure("Error message")) instead. There's literally no reason to be writing assert(false, …) beyond lack of knowledge of assertionFailure(_:).

I don't see any configuration necessary here, and this should be opt-out because it's generally useful and the only reason to disable it is because you have hundreds of violations and don't want to fix them.

rule-request

Most helpful comment

@ornithocoder I have no plans on doing this myself, so please go ahead.

All 2 comments

Hi @kballard, do you have plans to work on it? Otherwise I'll take it.

@ornithocoder I have no plans on doing this myself, so please go ahead.

Was this page helpful?
0 / 5 - 0 ratings