
## Review A dedicated reviewer checked the rule description successfully for: - [x] logical errors and incorrect information - [x] information gaps and missing content - [x] text style and tone - [x] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
80 lines
1.9 KiB
Plaintext
80 lines
1.9 KiB
Plaintext
include::../rationale.adoc[]
|
|
|
|
=== Exceptions
|
|
|
|
Simple `for-in` loop counters are ignored by this rule because while they are often legitimately unused, their declaration is required by the syntax.
|
|
|
|
[source,swift]
|
|
----
|
|
for i in 1...10 { // Ignored
|
|
print("Hello! ");
|
|
}
|
|
----
|
|
|
|
include::../how-to-fix-it.adoc[]
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,swift,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
public func numberOfMinutes(hours:Int) -> Int {
|
|
var seconds = 0 // Noncompliant - seconds is unused
|
|
return hours * 60;
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,swift,diff-id=1,diff-type=compliant]
|
|
----
|
|
public func numberOfMinutes(hours:Int) -> Int{
|
|
return hours * 60
|
|
}
|
|
----
|
|
|
|
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[]
|