rspec/rules/S1481/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

82 lines
1.9 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
[source,swift]
----
public func numberOfMinutes(hours:Int) -> Int {
var seconds = 0 // seconds is never used
return hours * 60;
}
----
=== Compliant solution
[source,swift]
----
public func numberOfMinutes(hours:Int) -> Int{
return hours * 60
}
----
=== 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! ");
}
for (a, b) in someElements { // Noncompliant; b unused
print(a)
}
----
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[]