mirror of
https://github.com/github/codeql.git
synced 2026-07-21 11:18:20 +02:00
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.
52 lines
1.6 KiB
Plaintext
52 lines
1.6 KiB
Plaintext
/**
|
|
* @name Omitted array element
|
|
* @description Omitted elements in array literals are easy to miss and should not be used.
|
|
* @kind problem
|
|
* @problem.severity recommendation
|
|
* @id js/omitted-array-element
|
|
* @tags maintainability
|
|
* readability
|
|
* language-features
|
|
* @precision low
|
|
*/
|
|
|
|
import javascript
|
|
|
|
/**
|
|
* An initial omitted element in an array expression.
|
|
*
|
|
* This is represented by the corresponding array expression, with a special
|
|
* `hasLocationInfo` implementation that assigns it a location covering the
|
|
* first omitted array element.
|
|
*/
|
|
class OmittedArrayElement extends ArrayExpr {
|
|
int idx;
|
|
|
|
OmittedArrayElement() { idx = min(int i | elementIsOmitted(i)) }
|
|
|
|
/**
|
|
* Holds if this element is at the specified location.
|
|
* The location spans column `startcolumn` of line `startline` to
|
|
* column `endcolumn` of line `endline` in file `filepath`.
|
|
* For more information, see
|
|
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
|
|
*/
|
|
predicate hasLocationInfo(
|
|
string filepath, int startline, int startcolumn, int endline, int endcolumn
|
|
) {
|
|
exists(Token pre, Location before, Location after |
|
|
idx = 0 and pre = getFirstToken()
|
|
or
|
|
pre = getElement(idx - 1).getLastToken().getNextToken()
|
|
|
|
|
before = pre.getLocation() and
|
|
after = pre.getNextToken().getLocation() and
|
|
before.hasLocationInfo(filepath, startline, startcolumn, _, _) and
|
|
after.hasLocationInfo(_, _, _, endline, endcolumn)
|
|
)
|
|
}
|
|
}
|
|
|
|
from OmittedArrayElement ae
|
|
select ae, "Avoid omitted array elements."
|