rspec/rules/S1716/python/rule.adoc

66 lines
1.8 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
``++break++`` and ``++continue++`` are unstructured control flow statements which make code harder to read. Additionally, more recent versions of Python raise a SyntaxError when modules containing ``++break++`` or ``++continue++`` outside of a loop are imported.
Therefore, these statements should not be used outside of loops.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,python]
2021-04-28 16:49:39 +02:00
----
narg=len(sys.argv)
if narg == 1:
print('@Usage: input_filename nelements nintervals')
break
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,python]
2021-04-28 16:49:39 +02:00
----
if narg == 1:
print('@Usage: input_filename nelements nintervals')
sys.exit()
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this "xxx" statement
'''
== Comments And Links
(visible only on this page)
=== is related to: S910
=== on 4 Nov 2014, 15:59:14 Ann Campbell wrote:
pylint:E0103
=== on 9 May 2016, 15:41:47 Evgeny Mandrikov wrote:
I don't know any C/{cpp} compiler, which will allow to use "continue" outside of loop and "break" outside of switch and loop, hence not applicable.
=== on 9 May 2016, 15:44:26 Evgeny Mandrikov wrote:
Note that PC-Lint error codes from 1 to 199 for C and from 1001 to 1199 for {cpp} are syntax errors.
=== on 16 May 2016, 17:06:00 Ann Campbell wrote:
\[~evgeny.mandrikov] I guess this means that PC-Lint doesn't expect compilable code?
=== on 16 May 2016, 17:14:19 Evgeny Mandrikov wrote:
\[~ann.campbell.2] I suppose that it expects for proper analysis in general, but when this is not the case it generates more precise "parse error".
=== on 16 May 2016, 17:50:32 Ann Campbell wrote:
For the record PC-Lint rules in these ranges are Syntax errors: 1-199, 1001-1199.
endif::env-github,rspecator-view[]