rspec/rules/S1481/swift/rule.adoc

80 lines
1.9 KiB
Plaintext
Raw Normal View History

include::../rationale.adoc[]
=== Exceptions
2020-06-30 12:47:33 +02:00
Simple `for-in` loop counters are ignored by this rule because while they are often legitimately unused, their declaration is required by the syntax.
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,swift]
2020-06-30 12:47:33 +02:00
----
for i in 1...10 { // Ignored
print("Hello! ");
2020-06-30 12:47:33 +02:00
}
----
include::../how-to-fix-it.adoc[]
2020-06-30 12:47:33 +02:00
=== Code examples
==== Noncompliant code example
[source,swift,diff-id=1,diff-type=noncompliant]
2020-06-30 12:47:33 +02:00
----
public func numberOfMinutes(hours:Int) -> Int {
var seconds = 0 // Noncompliant - seconds is unused
return hours * 60;
2020-06-30 12:47:33 +02:00
}
----
==== Compliant solution
[source,swift,diff-id=1,diff-type=compliant]
2020-06-30 12:47:33 +02:00
----
public func numberOfMinutes(hours:Int) -> Int{
return hours * 60
2020-06-30 12:47:33 +02:00
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
=== on 3 Jul 2015, 08:42:34 Elena Vilchik wrote:
\[~ann.campbell.2] Could you "fix" exception I've just added to this rule?
=== on 6 Jul 2015, 14:38:36 Ann Campbell wrote:
double-check me, [~elena.vilchik]
=== on 6 Jul 2015, 14:48:28 Elena Vilchik wrote:
\[~ann.campbell.2] LGTM. Only thing i'm not sure: implementation ignores "lonely" counters but raises issue for other (tuples). WDYT should we put such details in description? (from my point of view we shouldn't, but how knows :))
----
for i in 1...10 { // Ignored
print("Hello! ");
}
for (a, b) in someElements { // issue for "b"
print(a)
}
----
=== on 6 Jul 2015, 14:55:18 Ann Campbell wrote:
Mention added [~elena.vilchik]. We'd have gotten questions/complaints eventually otherwise. :-)
I'm assuming/hoping that "lonely" is the recognized term for this type of counter in Swift circles?
=== on 6 Jul 2015, 15:02:26 Elena Vilchik wrote:
\[~ann.campbell.2] No :) "lonely" is just my explanation. I replaced it with ``++simple++``.
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]