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

48 lines
1.0 KiB
Plaintext

== Why is this an issue?
The conventional expectation of operators that end with ``++=++``, such as ``+++=++``, ``++-=++``, ``++*=++``, and so on, is that the result of the operation will be assigned to the operand on the left-hand side of the operator.
Define any other behavior and you almost guarantee that the users of your code will misunderstand and therefore misuse your operator.
=== Noncompliant code example
[source,swift]
----
func **= (p1:Int, p2:Int) -> Int { // Noncompliant. Change operator name or update value of first parameter
return p1 ** p2
}
func => (p1:Int, p2:Int) -> Int { // Compliant; doesn't end with '='
return p1 ** p1 ** p2
}
----
=== Compliant solution
[source,swift]
----
func **= (inout p1:Int, p2:Int) {
p1 = p1 ** p2
}
func => (p1:Int, p2:Int) -> Int {
return p1 ** p1 ** p2
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Assign the value of the operation to "xxx".
endif::env-github,rspecator-view[]