Files
codeql/javascript/ql/src/Statements/EphemeralLoop.ql
Max Schaefer a803120414 Lower precision for a number of queries.
These queries are currently run by default, but don't have their results displayed.

Looking through results on LGTM.com, they are either false positives (e.g., `BitwiseSignCheck` which flags many perfectly harmless operations and `CompareIdenticalValues` which mostly flags NaN checks) or harmless results that developers are unlikely to care about (e.g., `EmptyArrayInit` or `MisspelledIdentifier`).

With this PR, the only queries that are still run but not displayed are security queries, where different considerations may apply.
2020-05-19 13:43:17 +01:00

24 lines
753 B
Plaintext

/**
* @name Loop body executes at most once
* @description A loop that executes at most once is confusing and should be rewritten
* as a conditional.
* @kind problem
* @problem.severity recommendation
* @id js/single-run-loop
* @tags readability
* @precision low
*/
import javascript
import semmle.javascript.RestrictedLocations
import semmle.javascript.frameworks.Emscripten
from LoopStmt l, BasicBlock body
where
body = l.getBody().getBasicBlock() and
not body.getASuccessor+() = body and
not l instanceof EnhancedForLoop and
// Emscripten generates lots of `do { ... } while(0);` loops, so exclude
not l.getTopLevel() instanceof EmscriptenGeneratedToplevel
select l.(FirstLineOf), "This loop executes at most once."