rspec/rules/S1155/swift/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

41 lines
925 B
Plaintext

== Why is this an issue?
Using ``++[Int]().count++`` to test for emptiness works, but using ``++[Int]().isEmpty++`` makes the code more readable and can be more performant. The time complexity of any ``++isEmpty++`` implementation should be ``++O(1)++`` whereas some implementations of ``++count()++`` can be ``++O(n)++``.
=== Noncompliant code example
[source,swift]
----
if (arr.count == 0) { // Noncompliant
/* ... */
}
----
=== Compliant solution
[source,swift]
----
if (arr.isEmpty) {
/* ... */
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
=== on 8 Jul 2016, 20:40:54 Ann Campbell wrote:
https://github.com/realm/SwiftLint/blob/master/Source/SwiftLintFramework/Rules/EmptyCountRule.swift
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]