-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add php to rule S5797 * Create PHP rule S5797 * Update PHP rule S5797 examples * Update rule S5797 includes --------- Co-authored-by: rudy-regazzoni-sonarsource <[email protected]> Co-authored-by: GabinL21 <[email protected]>
- Loading branch information
1 parent
c6798c1
commit 5273746
Showing
5 changed files
with
83 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This rule raises an issue when a constant expression is used as a condition in an ``++if++``, ``++elif++``, a conditional expression or other boolean expressions. | ||
|
||
== Why is this an issue? | ||
|
||
When a constant is used as a condition, either it has no effect on the execution flow and it can be removed, or some code will never be executed and it is a bug. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
include::../description.adoc[] | ||
|
||
== How to fix it | ||
|
||
=== Code examples | ||
|
||
==== Noncompliant code example | ||
|
||
[source,php,diff-id=1,diff-type=noncompliant] | ||
---- | ||
function foo() { | ||
if (true) { // Noncompliant: the condition is always true | ||
return 1; | ||
} else { | ||
return 2; | ||
} | ||
} | ||
---- | ||
|
||
==== Compliant solution | ||
|
||
[source,php,diff-id=1,diff-type=compliant] | ||
---- | ||
function foo() { | ||
$a = bar(); | ||
if ($a) { | ||
return 1; | ||
} else { | ||
return 2; | ||
} | ||
} | ||
---- | ||
|
||
include::../rule.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
include::../rule.adoc[] | ||
include::../description.adoc[] | ||
|
||
=== Code examples | ||
|
||
==== Noncompliant code example | ||
|
||
ifdef::env-github,rspecator-view[] | ||
[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 | ||
---- | ||
|
||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
include::../message.adoc[] | ||
==== Compliant solution | ||
|
||
include::../highlighting.adoc[] | ||
[source,python,diff-id=1,diff-type=compliant] | ||
---- | ||
def foo(): | ||
a = bar() | ||
if a: | ||
return 1 | ||
else: | ||
return 2 | ||
---- | ||
|
||
''' | ||
== Comments And Links | ||
(visible only on this page) | ||
|
||
include::../comments-and-links.adoc[] | ||
== Resources | ||
|
||
endif::env-github,rspecator-view[] | ||
=== 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[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,17 @@ | ||
This rule raises an issue when a constant expression is used as a condition in an ``++if++``, ``++elif++``, a conditional expression or other boolean expressions. | ||
ifdef::env-github,rspecator-view[] | ||
|
||
== Why is this an issue? | ||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
When a constant is used as a condition, either it has no effect on the execution flow and it can be removed, or some code will never be executed and it is a bug. | ||
include::./message.adoc[] | ||
|
||
include::./highlighting.adoc[] | ||
|
||
=== Noncompliant code example | ||
''' | ||
== Comments And Links | ||
(visible only on this page) | ||
|
||
[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::./comments-and-links.adoc[] | ||
|
||
endif::env-github,rspecator-view[] |