JS: rename query to "Loop iteration skipped due to shifting"

This commit is contained in:
Asger F
2019-01-02 11:34:06 +00:00
parent 8c3b44a525
commit 9f22da4557
11 changed files with 10 additions and 10 deletions

View File

@@ -13,7 +13,7 @@
| Double escaping or unescaping (`js/double-escaping`) | correctness, security, external/cwe/cwe-116 | Highlights potential double escaping or unescaping of special characters, indicating a possible violation of [CWE-116](https://cwe.mitre.org/data/definitions/116.html). Results are shown on LGTM by default. |
| Incomplete URL substring sanitization | correctness, security, external/cwe/cwe-020 | Highlights URL sanitizers that are likely to be incomplete, indicating a violation of [CWE-020](https://cwe.mitre.org/data/definitions/20.html). Results shown on LGTM by default. |
| Incorrect suffix check (`js/incorrect-suffix-check`) | correctness, security, external/cwe/cwe-020 | Highlights error-prone suffix checks based on `indexOf`, indicating a potential violation of [CWE-20](https://cwe.mitre.org/data/definitions/20.html). Results are shown on LGTM by default. |
| Missing index adjustment after concurrent modification (`js/missing-index-adjustment-after-concurrent-modification`) | correctness | Highlights code that removes an element from an array while iterating over it, causing the loop to skip over some elements. Results are shown on LGTM by default. |
| Loop iteration skipped due to shifting (`js/loop-iteration-skipped-due-to-shifting`) | correctness | Highlights code that removes an element from an array while iterating over it, causing the loop to skip over some elements. Results are shown on LGTM by default. |
| Useless comparison test (`js/useless-comparison-test`) | correctness | Highlights code that is unreachable due to a numeric comparison that is always true or always false. Results are shown on LGTM by default. |
## Changes to existing queries

View File

@@ -38,7 +38,7 @@ Determine what the loop is supposed to do:
In this example, a function is intended to remove "<code>..</code>" parts from a path:
</p>
<sample src="examples/MissingIndexAdjustmentAfterConcurrentModification.js" />
<sample src="examples/LoopIterationSkippedDueToShifting.js" />
<p>
However, whenever the input contain two "<code>..</code>" parts right after one another, only the first will be removed.
@@ -51,13 +51,13 @@ index 0 and will therefore be skipped.
One way to avoid this is to decrement the loop counter after removing an element from the array:
</p>
<sample src="examples/MissingIndexAdjustmentAfterConcurrentModificationGood.js" />
<sample src="examples/LoopIterationSkippedDueToShiftingGood.js" />
<p>
Alternatively, use the <code>filter</code> method:
</p>
<sample src="examples/MissingIndexAdjustmentAfterConcurrentModificationGoodFilter.js" />
<sample src="examples/LoopIterationSkippedDueToShiftingGoodFilter.js" />
</example>
<references>

View File

@@ -1,10 +1,10 @@
/**
* @name Missing index adjustment after concurrent modification
* @name Loop iteration skipped due to shifting.
* @description Removing elements from an array while iterating over it can cause the loop to skip over some elements,
* unless the loop index is decremented accordingly.
* @kind problem
* @problem.severity warning
* @id js/missing-index-adjustment-after-concurrent-modification
* @id js/loop-iteration-skipped-due-to-shifting
* @tags correctness
* @precision high
*/

View File

@@ -0,0 +1,3 @@
| tst.js:4:27:4:44 | parts.splice(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent array item to be skipped. |
| tst.js:13:29:13:46 | parts.splice(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent array item to be skipped. |
| tst.js:24:9:24:26 | parts.splice(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent array item to be skipped. |

View File

@@ -0,0 +1 @@
Statements/LoopIterationSkippedDueToShifting.ql

View File

@@ -1,3 +0,0 @@
| tst.js:4:27:4:44 | parts.splice(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent item to be skipped. |
| tst.js:13:29:13:46 | parts.splice(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent item to be skipped. |
| tst.js:24:9:24:26 | parts.splice(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent item to be skipped. |