![github-actions[bot]](/assets/img/avatar_default.png)
* Add php to rule S5797 * Create PHP rule S5797 * Update PHP rule S5797 examples * Update rule S5797 includes --------- Co-authored-by: rudy-regazzoni-sonarsource <rudy-regazzoni-sonarsource@users.noreply.github.com> Co-authored-by: GabinL21 <gabin.laigle21@gmail.com>
39 lines
713 B
Plaintext
39 lines
713 B
Plaintext
include::../description.adoc[]
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,python,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
def foo():
|
|
a = True
|
|
if a: # Noncompliant: the condition is always true
|
|
return 1
|
|
else:
|
|
return 2
|
|
----
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
[source,python,diff-id=1,diff-type=compliant]
|
|
----
|
|
def foo():
|
|
a = bar()
|
|
if a:
|
|
return 1
|
|
else:
|
|
return 2
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* Python documentation - https://www.python.org/dev/peps/pep-0285/[PEP 285 - Adding a bool type]
|
|
* Python documentation - https://docs.python.org/3/library/stdtypes.html#truth-value-testing[Python documentation - Truth Value Testing]
|
|
|
|
include::../rule.adoc[]
|