rspec/rules/S3440/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

56 lines
877 B
Plaintext

== Why is this an issue?
There's no point in checking a variable against the value you're about to assign it. Save the cycles and lines of code, and simply perform the assignment.
=== Noncompliant code example
[source,text]
----
if (x != a) // Noncompliant; why bother?
{
x = a;
}
----
=== Compliant solution
[source,text]
----
x = a;
----
=== Exceptions
Properties and checks inside setters are excluded from this rule because they could have side effects and removing the check could lead to undesired side effects.
[source,text]
----
if (MyProperty != a)
{
MyProperty = a; // Compliant because the setter could be expensive call
}
----
[source,text]
----
private int myField;
public int SomeProperty
{
get
{
return myField;
}
set
{
if (myField != value)
{
myField = value;
}
}
}
----