@@ -50,6 +50,22 @@ ruleTester.run("no-loop-func", rule, {
50
50
code : "for (const i of {}) { (function() { i; }) }" ,
51
51
languageOptions : { ecmaVersion : 6 } ,
52
52
} ,
53
+ {
54
+ code : "for (using i of foo) { (function() { i; }) }" ,
55
+ languageOptions : { ecmaVersion : 2026 } ,
56
+ } ,
57
+ {
58
+ code : "for (await using i of foo) { (function() { i; }) }" ,
59
+ languageOptions : { ecmaVersion : 2026 } ,
60
+ } ,
61
+ {
62
+ code : "for (var i = 0; i < 10; ++i) { using foo = bar(i); (function() { foo; }) }" ,
63
+ languageOptions : { ecmaVersion : 2026 } ,
64
+ } ,
65
+ {
66
+ code : "for (var i = 0; i < 10; ++i) { await using foo = bar(i); (function() { foo; }) }" ,
67
+ languageOptions : { ecmaVersion : 2026 } ,
68
+ } ,
53
69
{
54
70
code : "for (let i = 0; i < 10; ++i) { for (let x in xs.filter(x => x != i)) { } }" ,
55
71
languageOptions : { ecmaVersion : 6 } ,
@@ -170,7 +186,7 @@ ruleTester.run("no-loop-func", rule, {
170
186
current.c;
171
187
current.d;
172
188
})();
173
-
189
+
174
190
current = current.upper;
175
191
}
176
192
` ,
@@ -208,6 +224,42 @@ ruleTester.run("no-loop-func", rule, {
208
224
` ,
209
225
languageOptions : { ecmaVersion : 6 } ,
210
226
} ,
227
+ {
228
+ code : `
229
+ const foo = bar;
230
+
231
+ for (var i = 0; i < 5; i++) {
232
+ arr.push(() => foo);
233
+ }
234
+
235
+ foo = baz; // This is a runtime error, but not concern of this rule. For this rule, variable 'foo' is constant.
236
+ ` ,
237
+ languageOptions : { ecmaVersion : 6 } ,
238
+ } ,
239
+ {
240
+ code : `
241
+ using foo = bar;
242
+
243
+ for (var i = 0; i < 5; i++) {
244
+ arr.push(() => foo);
245
+ }
246
+
247
+ foo = baz; // This is a runtime error, but not concern of this rule. For this rule, variable 'foo' is constant.
248
+ ` ,
249
+ languageOptions : { ecmaVersion : 2026 } ,
250
+ } ,
251
+ {
252
+ code : `
253
+ await using foo = bar;
254
+
255
+ for (var i = 0; i < 5; i++) {
256
+ arr.push(() => foo);
257
+ }
258
+
259
+ foo = baz; // This is a runtime error, but not concern of this rule. For this rule, variable 'foo' is constant.
260
+ ` ,
261
+ languageOptions : { ecmaVersion : 2026 } ,
262
+ } ,
211
263
] ,
212
264
invalid : [
213
265
{
@@ -471,7 +523,7 @@ ruleTester.run("no-loop-func", rule, {
471
523
current;
472
524
arr.push(f);
473
525
})();
474
-
526
+
475
527
current = current.upper;
476
528
}
477
529
` ,
@@ -615,7 +667,7 @@ ruleTester.run("no-loop-func", rule, {
615
667
616
668
for (var i = 0; i < 5; i++) {
617
669
arr.push((() => {
618
- return () =>
670
+ return () =>
619
671
(() => i)();
620
672
})());
621
673
}
@@ -666,7 +718,7 @@ ruleTester.run("no-loop-func", rule, {
666
718
return i;
667
719
})();
668
720
})();
669
-
721
+
670
722
}
671
723
` ,
672
724
languageOptions : { ecmaVersion : 2022 } ,
@@ -839,7 +891,7 @@ ruleTesterTypeScript.run("no-loop-func", rule, {
839
891
// ConfiguredType is in globals, UnconfiguredType is not
840
892
// Both should be considered safe as they are type references
841
893
const process = (configItem: ConfiguredType, unconfigItem: UnconfiguredType) => {
842
- return {
894
+ return {
843
895
config: configItem.value,
844
896
unconfig: unconfigItem.value
845
897
};
@@ -892,14 +944,14 @@ ruleTesterTypeScript.run("no-loop-func", rule, {
892
944
id: number;
893
945
name: string;
894
946
}
895
-
947
+
896
948
const items: Item[] = [];
897
949
for (var i = 0; i < 10; i++) {
898
950
items.push({
899
951
id: i,
900
952
name: "Item " + i
901
953
});
902
-
954
+
903
955
const process = function(callback: (item: Item) => void): void {
904
956
callback({ id: i, name: "Item " + i });
905
957
};
@@ -916,7 +968,7 @@ ruleTesterTypeScript.run("no-loop-func", rule, {
916
968
{
917
969
code : `
918
970
type Processor<T> = (item: T) => void;
919
-
971
+
920
972
for (var i = 0; i < 10; i++) {
921
973
const processor: Processor<number> = (item) => {
922
974
return item + i;
0 commit comments