rspec/rules/S1721/python/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

62 lines
1.7 KiB
Plaintext

== Why is this an issue?
Parentheses are not required after the ``++assert++``, ``++del++``, ``++elif++``, ``++except++``, ``++for++``, ``++if++``, ``++in++``, ``++not++``, ``++raise++``, ``++return++``, ``++while++``, and ``++yield++`` keywords, and using them unnecessarily impairs readability. They should therefore be omitted.
=== Noncompliant code example
[source,python]
----
x = 1
while (x < 10):
print "x is now %d" % (x)
x += 1
----
=== Compliant solution
[source,python]
----
x = 1
while x < 10:
print "x is now %d" % (x)
x += 1
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove the parentheses after this "XXX" keyword
'''
== Comments And Links
(visible only on this page)
=== on 5 May 2017, 15:59:08 Pierre-Yves Nicolas wrote:
\[~ann.campbell.2] This rule is deprecated in favor of RSPEC-1110. However, the scope of RSPEC-1110 was reduced. Should we still deprecate this rule?
=== on 9 May 2017, 09:15:00 Freddy Mallet wrote:
Indeed [~pierre-yves.nicolas] and [~ann.campbell.2], I don't think there is any remaining overlap between this rule and RSPEC-1110.
=== on 23 Jul 2020, 11:15:39 Nicolas Harraudeau wrote:
This rule is deprecated because it raises mostly false positives on tuples and unpacking. Ex: `return (a,b)` or `for (a,b) in x:`
Also it provides very little value as there can be cases when parentheses improve readability.
Some cases deserve dedicated rules:
* S5905 "Assert should not be called on a tuple literal": it is a common bug, not a code smell.
* A rule should be created later to detect when single element tuple was intended. ex: `a = (b)` when developer probably wanted `a = (b,)`
endif::env-github,rspecator-view[]