rspec/rules/S2772/python/rule.adoc

49 lines
1.0 KiB
Plaintext
Raw Normal View History

2023-08-07 14:46:53 +02:00
This rule raises an issue when a `pass` statement is redundant.
== Why is this an issue?
2023-08-07 14:46:53 +02:00
The use of a `pass` statement where it is not required by the syntax is redundant. It makes the code less readable and its intent confusing.
To fix this issue, remove `pass` statements that do not affect the behaviour of the program.
2021-04-28 16:49:39 +02:00
2023-08-07 14:46:53 +02:00
=== Code examples
2023-08-07 14:46:53 +02:00
==== Noncompliant code example
2021-04-28 16:49:39 +02:00
2023-08-07 14:46:53 +02:00
[source,python,diff-id=1,diff-type=noncompliant]
2021-04-28 16:49:39 +02:00
----
2023-08-07 14:46:53 +02:00
def foo(arg):
print(arg)
pass # Noncompliant: the `pass` statement is not needed as it does not change the behaviour of the program.
2021-04-28 16:49:39 +02:00
----
2023-08-07 14:46:53 +02:00
==== Compliant solution
2021-04-28 16:49:39 +02:00
2023-08-07 14:46:53 +02:00
[source,python,diff-id=1,diff-type=compliant]
2021-04-28 16:49:39 +02:00
----
2023-08-07 14:46:53 +02:00
def foo(arg):
print(arg)
2021-04-28 16:49:39 +02:00
----
2023-08-07 14:46:53 +02:00
== Resources
=== Documentation
* Python Documentation - https://docs.python.org/3/reference/simple_stmts.html#the-pass-statement[The pass statement]
ifdef::env-github,rspecator-view[]
'''
2023-08-07 14:46:53 +02:00
== Implementation Specification
(visible only on this page)
=== Message
Remove this unneeded "pass".
endif::env-github,rspecator-view[]