42 lines
996 B
Plaintext
42 lines
996 B
Plaintext
There's no point in forcing the overhead of a function or method call for a function that always returns the same constant value. Even worse, the fact that a function call must be made will likely mislead developers who call the method thinking that something more is done. Declare a constant instead.
|
|
|
|
|
|
This rule raises an issue on functions that contain only one statement: the ``++return++`` of a constant value.
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,swift]
|
|
----
|
|
func getBestNumber() -> Int {
|
|
return 12 // Noncompliant
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,swift]
|
|
----
|
|
let bestNumber = 12;
|
|
----
|
|
|
|
== Exceptions
|
|
|
|
Methods which are members of a class having a type inheritance clause are ignored.
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|