rspec/rules/S1854/python/rule.adoc

55 lines
1.0 KiB
Plaintext
Raw Normal View History

2023-10-13 12:26:37 +02:00
include::../why.adoc[]
2023-10-13 12:26:37 +02:00
=== Exceptions
This rule ignores initializations to `-1`, `0`, `1`, `None`, `True`, `False` and `""`.
No issue will be raised on unpacked variables.
2020-06-30 12:47:33 +02:00
2023-10-13 12:26:37 +02:00
include::../howtofixit.adoc[]
2020-06-30 12:47:33 +02:00
2023-10-13 12:26:37 +02:00
=== Code examples
==== Noncompliant code example
[source,python,diff-id=1,diff-type=noncompliant]
2020-06-30 12:47:33 +02:00
----
def func(a, b, compute):
i = a + b # Noncompliant; calculation result not used before value is overwritten
i = compute()
return i
2020-06-30 12:47:33 +02:00
----
2023-10-13 12:26:37 +02:00
==== Compliant solution
2020-06-30 12:47:33 +02:00
2023-10-13 12:26:37 +02:00
[source,python,diff-id=1,diff-type=compliant]
2020-06-30 12:47:33 +02:00
----
def func(a, b, compute):
i = a + b
i += compute()
return i
----
2023-10-13 12:26:37 +02:00
include::../see.adoc[]
2021-02-02 15:02:10 +01:00
2023-10-13 12:26:37 +02:00
=== Related rules
2020-06-30 12:47:33 +02:00
2023-10-13 12:26:37 +02:00
* S1763 - All code should be reachable
* S3516 - Functions returns should not be invariant
* 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[]