Files
codeql/javascript/ql/src/Statements/UselessComparisonTest.qhelp
Josh Soref e8754967ea spelling: explaining
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-10-11 00:23:36 -04:00

48 lines
1.1 KiB
XML

<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
If a condition always evaluates to true or always evaluates to false, this often indicates
incomplete code or a latent bug, and it should be examined carefully.
</p>
</overview>
<recommendation>
<p>
Examine the surrounding code to determine why the condition is redundant. If it is no
longer needed, remove it.
</p>
<p>
If the check is needed to guard against <code>NaN</code> values, insert a comment explaining the possibility of <code>NaN</code>.
</p>
</recommendation>
<example>
<p>
The following example finds the index of an element in a given slice of the array:
</p>
<sample src="examples/UselessComparisonTest.js" />
<p>
The condition <code>i &lt; end</code> at the end is always false, however. The code can be clarified if the
redundant condition is removed:
</p>
<sample src="examples/UselessComparisonTestGood.js" />
</example>
<references>
<li>Mozilla Developer Network: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Truthy">Truthy</a>,
<a href="https://developer.mozilla.org/en-US/docs/Glossary/Falsy">Falsy</a>.</li>
</references>
</qhelp>