rspec/rules/S1772/rule.adoc

26 lines
720 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-01-27 13:42:22 +01:00
The result of the comparison is the same, regardless of whether the constant is on the left or right-hand side. But following this convention will help pinpoint the occasional error where ``++=++`` (assignment) is substituted for ``++==++`` (comparison).
2020-06-30 12:47:33 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:47:33 +02:00
If the constant is on the right-hand side of the expression in such cases, the code will still compile and run - just not as expected. If the constant is on the left-hand side, the error will be caught at the first attempt to compile.
=== Noncompliant code example
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:47:33 +02:00
----
if ( var == constant )
if ( pointer == NULL )
----
=== Compliant solution
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:47:33 +02:00
----
if ( constant == var )
if ( NULL == pointer )
----