rspec/rules/S2961/swift/rule.adoc

62 lines
1.3 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
You can't create a variable named "for". Unless you put backticks (``++`++``) around it.
Since that would be the first step down a slippery slope of hopeless confusion, backticks should be removed from identifier names - whether they're keywords or not - and the identifiers renamed as required.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
var `for` = 1 // Noncompliant
for (var `in` = 0; `in` < 10 && `for` > 0; `in`++) { // Noncompliant
// ...
}
var `x` = "hello" // Noncompliant; why would you do this?
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
var i = a
for (var j=0; j< 10; j++) {
// ...
}
var x = "hello"
----
2021-04-28 16:49:39 +02:00
== Exceptions
When Objective-C libraries are used in Swift, backticks may be needed around parameter names which are keywords in Swift but not in Objective C. Therefore this rule ignores backticks around parameter names.
----
var protectionSpace: NSURLProtectionSpace = NSURLProtectionSpace(
host: host,
port: port,
`protocol`: prot, // Compliant
realm: nil,
authenticationMethod: authenticationMethod
);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]