Any statement, other than a pass
, ...
(ellipsis) or an empty statement (i.e. a single semicolon ";
"), which has no side effect and does not result in a change of control flow will normally indicate a programming error, and therefore should be refactored.
== Noncompliant Code Example
----
a == 1 # Noncompliant; was assignment intended?
a < b # Noncompliant; have we forgotten to assign the result to a variable?
----
== Exceptions
*Strings*
Some projects use string literals as comments. By default, this rule will not raise an issue on these strings. Reporting on string literals can be enabled by setting the rule parameter "reportOnStrings" to "true".
----
class MyClass:
myattr = 42
"""This is an attribute""" # Noncompliant by default. Set "reportOnStrings" to "false"
----
*Operators*
By default, this rule considers that no arithmetic operator has a side effect. Some rare projects redefine operators and add a side effect. You can list such operators in the rule parameter "ignoredOperators".
----
def process(p, beam):
"""
Apache Beam redefines "|" and ">>" operators and they have a side effect.
Thus for Apache Beam projects "ignoredOperators"should be set to "|,>>"
"""
p | "create" >> beam.Create() # Noncompliant by default
----
include::../see.adoc[]