
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.
65 lines
1.4 KiB
Plaintext
65 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Function, methods and lambdas should not have too many mandatory parameters, i.e. parameters with no default value. Calling them will require code difficult to read and maintain. To solve this problem you could wrap some parameters in an object, split the function into simpler functions with less parameters or provide default values for some parameters.
|
|
|
|
=== Noncompliant code example
|
|
|
|
With a maximum number of 4 parameters:
|
|
|
|
[source,python]
|
|
----
|
|
def do_something(param1, param2, param3, param4, param5): # Noncompliant
|
|
...
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
def do_something(param1, param2, param3, param4):
|
|
...
|
|
|
|
# Or
|
|
|
|
def do_something(param1, param2, param3, param4, param5="a default value"):
|
|
...
|
|
----
|
|
|
|
|
|
=== Exceptions
|
|
|
|
The first argument of non-static methods, i.e. ``++self++`` or ``++cls++``, is not counted as it is mandatory and it is passed automatically.
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
\[Function|Constructor|Method|Lambda] "XXXX" has {0} mandatory parameters, which is greater than the {1} authorized.
|
|
|
|
|
|
=== Parameters
|
|
|
|
.max
|
|
****
|
|
|
|
----
|
|
7
|
|
----
|
|
|
|
Maximum authorized number of mandatory parameters
|
|
****
|
|
|
|
|
|
=== Highlighting
|
|
|
|
* Primary location: The function/method name or the lambda keyword
|
|
* Secondary location: Mandatory parameters. No message.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|