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

62 lines
2.1 KiB
Plaintext

== Why is this an issue?
Conditional compilation is generally recognized as a bad practice that is occasionally necessary when dealing with platform-specific code. As much as possible, code should be refactored to minimize or eliminate conditionally-compiled, platform-specific code because even when necessary and well-intentioned, such code segments can leave your codebase in a hopeless tangle.
=== Noncompliant code example
[source,swift]
----
#if os(OSX) // Noncompliant
let a = 2
#else
let a = 3
#endif
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Refactor the code to not need these conditional compilation directives.
'''
== Comments And Links
(visible only on this page)
=== on 23 Jun 2015, 07:59:51 Elena Vilchik wrote:
\[~ann.campbell.2] Since Swift 2.0 (which is not actually released) there is feature "availability checking".
http://www.hackingwithswift.com/new-syntax-swift-2-availability-checking
----
if #available(iOS 9, *) {
// use UIStackView
} else {
// show sad face emoji
}
----
WDYT May be it's worth mentioning in this rule? (smth like "But to able to run some pieces of code only on specific OS releases you can use availability checking (since Swift 2.0)")
UPDATE I've attached screenshot from documentation (it's from book and it doesn't allow me copy content)
=== on 23 Jun 2015, 14:22:21 Ann Campbell wrote:
I like it [~elena.vilchik] but I'm wondering about timing. Are you not likely to implement this rule until after Swift 2.0 is released?
=== on 24 Jun 2015, 08:04:59 Elena Vilchik wrote:
\[~ann.campbell.2] ok, let's keep it for Swift 2.0 release (ticket created SWIFT-162)
=== on 10 Dec 2015, 15:02:00 Ann Campbell wrote:
expanded per your request [~elena.vilchik]
=== on 10 Dec 2015, 15:15:10 Elena Vilchik wrote:
\[~ann.campbell.2] Actually availability-checking should be compliant :) This piece should help people facing this rule to fix the issue by replacing preprocessor directives by ``++if #available ...++``.
endif::env-github,rspecator-view[]