rspec/rules/S1854/swift/rule.adoc
2023-10-13 12:26:37 +02:00

55 lines
983 B
Plaintext

include::../why.adoc[]
=== Exceptions
This rule ignores initializations to `0`, `1`, `nil`, `true`, `false` and `""`.
include::../howtofixit.adoc[]
=== Code examples
==== Noncompliant code example
[source,swift,diff-id=1,diff-type=noncompliant]
----
func foo(y: Int) -> Int {
var x = 100 // Noncompliant: dead store
x = 150 // Noncompliant: dead store
x = 200
return x + y
}
----
==== Compliant solution
[source,swift,diff-id=1,diff-type=compliant]
----
func foo(y: Int) -> Int {
var x = 200 // Compliant: no unnecessary assignment
return x + y
}
----
include::../see.adoc[]
=== Related rules
* S1763 - All code should be reachable
* S3626 - Jump statements should not be redundant
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[]