rspec/rules/S1772/rule.adoc

26 lines
720 B
Plaintext

== Why is this an issue?
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).
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
[source,text]
----
if ( var == constant )
if ( pointer == NULL )
----
=== Compliant solution
[source,text]
----
if ( constant == var )
if ( NULL == pointer )
----