Skip to content

Commit 7292a76

Browse files
committed
JS: add test cases for false positives in loop-iteration-skipped-due-to-shifting
1 parent 538a5af commit 7292a76

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
| 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. |
22
| 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. |
33
| 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. |
4+
| tst.js:128:11:128:33 | pending ... e(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent array item to be skipped. |
5+
| tst.js:136:32:136:47 | toc.splice(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent array item to be skipped. |
6+
| tst.js:143:10:143:25 | toc.splice(i, 1) | Removing an array item without adjusting the loop index 'i' causes the subsequent array item to be skipped. |

javascript/ql/test/query-tests/Statements/LoopIterationSkippedDueToShifting/tst.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,28 @@ function inspectNextElement(string) {
121121
}
122122
return parts.join('/');
123123
}
124+
125+
function withTryCatch(pendingCSS) {
126+
for (let i = 0; i < pendingCSS.length; ++i) {
127+
try {
128+
pendingCSS.splice(i, 1); // $ SPURIOUS:Alert
129+
i -= 1;
130+
} catch (ex) {}
131+
}
132+
}
133+
134+
function andOperand(toc) {
135+
for (let i = 0; i < toc.length; i++) {
136+
toc[i].ignoreSubHeading && toc.splice(i, 1) && i--; // $ SPURIOUS:Alert
137+
}
138+
}
139+
140+
function ifStatement(toc) {
141+
for (let i = 0; i < toc.length; i++) {
142+
if(toc[i].ignoreSubHeading){
143+
if(toc.splice(i, 1)){ // $ SPURIOUS:Alert
144+
i--;
145+
}
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)