Skip to content

Commit 725ce17

Browse files
Replace Array.forEach with for...of loops (#3269)
1 parent 26c0602 commit 725ce17

79 files changed

Lines changed: 356 additions & 294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

oxlint.config.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { defineConfig } from "oxlint";
33

44
// These rules should probably be re-enabled eventually
55
const temporarilyDisabledRules = [
6-
"unicorn/no-array-for-each",
7-
"unicorn/no-array-reverse",
6+
// Requires es2023
87
"unicorn/no-array-sort",
8+
"unicorn/no-array-reverse",
99
];
1010

1111
const disabledRules = [
@@ -26,6 +26,7 @@ const disabledRules = [
2626
"eslint/no-continue",
2727
"eslint/no-eq-null",
2828
"eslint/no-lonely-if",
29+
"eslint/no-loop-func",
2930
"eslint/no-magic-numbers",
3031
"eslint/no-negated-condition",
3132
"eslint/no-plusplus",

packages/app-neovim/src/registerCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ export function registerCommands(
128128
"cursorless.documentationOpened": dummyCommandHandler,
129129
};
130130

131-
Object.entries(commands).forEach(([commandId, callback]) => {
131+
for (const [commandId, callback] of Object.entries(commands)) {
132132
getNeovimRegistry().registerCommand(commandId, callback);
133-
});
133+
}
134134
}
135135

136136
export function dummyCommandHandler(...args: any[]) {

packages/app-vscode/src/ReleaseNotes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ suite("release notes", () => {
157157
sinon.restore();
158158
});
159159

160-
testCases.forEach(({ input, expectedOutput }) => {
160+
for (const { input, expectedOutput } of testCases) {
161161
test(
162162
getTestName(input),
163163
asyncSafety(() => runTest(input, expectedOutput)),
164164
);
165-
});
165+
}
166166
});
167167

168168
function getTestName(input: Input) {

packages/app-vscode/src/createScopeVisualizer.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ export function createScopeVisualizer(
3333
);
3434
scopeVisualizer.start();
3535
currentScopeType = scopeType;
36-
listeners
37-
.slice()
38-
.forEach((listener) => listener(scopeType, visualizationType));
36+
for (const listener of listeners.slice()) {
37+
listener(scopeType, visualizationType);
38+
}
3939
},
4040

4141
stop() {
4242
scopeVisualizer?.dispose();
4343
scopeVisualizer = undefined;
4444
currentScopeType = undefined;
45-
listeners.slice().forEach((listener) => listener(undefined, undefined));
45+
for (const listener of listeners.slice()) {
46+
listener(undefined, undefined);
47+
}
4648
},
4749

4850
get scopeType() {

packages/app-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/VscodeFancyRangeHighlighterRenderer.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,27 @@ export class VscodeFancyRangeHighlighterRenderer {
6262
b.differentiatedStyle.differentiationIndex,
6363
);
6464

65-
decoratedRanges.forEach(
66-
({ differentiatedStyle: styleParameters, ranges }) => {
67-
const decorationType = this.decorationTypes.get(styleParameters);
65+
for (const { differentiatedStyle, ranges } of decoratedRanges) {
66+
const decorationType = this.decorationTypes.get(differentiatedStyle);
6867

69-
vscodeApi.editor.setDecorations(
70-
editor.vscodeEditor,
71-
decorationType,
72-
ranges.map(toVscodeRange),
73-
);
68+
vscodeApi.editor.setDecorations(
69+
editor.vscodeEditor,
70+
decorationType,
71+
ranges.map(toVscodeRange),
72+
);
7473

75-
untouchedDecorationTypes.delete(decorationType);
76-
},
77-
);
74+
untouchedDecorationTypes.delete(decorationType);
75+
}
7876

79-
untouchedDecorationTypes.forEach((decorationType) => {
77+
for (const decorationType of untouchedDecorationTypes) {
8078
editor.vscodeEditor.setDecorations(decorationType, []);
81-
});
79+
}
8280
}
8381

8482
dispose() {
85-
Array.from(this.decorationTypes.values()).forEach((decorationType) => {
83+
for (const decorationType of this.decorationTypes.values()) {
8684
decorationType.dispose();
87-
});
85+
}
8886
}
8987
}
9088

packages/app-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeScopeVisualizer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ export abstract class VscodeScopeVisualizer {
9797
}
9898

9999
dispose() {
100-
this.disposables.forEach((disposable) => disposable.dispose());
100+
for (const disposable of this.disposables) {
101+
disposable.dispose();
102+
}
101103
this.renderer?.dispose();
102104
this.scopeListenerDisposable?.dispose();
103105
}

packages/app-vscode/src/ide/vscode/VscodeEdit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ export async function vscodeEdit(
77
edits: Edit[],
88
): Promise<boolean> {
99
return await editor.edit((editBuilder) => {
10-
edits.forEach(({ range, text, isReplace }) => {
10+
for (const { range, text, isReplace } of edits) {
1111
if (text === "") {
1212
editBuilder.delete(toVscodeRange(range));
1313
} else if (range.isEmpty && !isReplace) {
1414
editBuilder.insert(toVscodePosition(range.start), text);
1515
} else {
1616
editBuilder.replace(toVscodeRange(range), text);
1717
}
18-
});
18+
}
1919
});
2020
}

packages/app-vscode/src/ide/vscode/VscodeFlashHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ export class VscodeFlashHandler {
3838
): void {
3939
const editorRangeMap = groupBy(ranges, ({ editor }) => editor.id);
4040

41-
this.ide.visibleTextEditors.forEach((editor) => {
41+
for (const editor of this.ide.visibleTextEditors) {
4242
const ranges = (editorRangeMap.get(editor.id) ?? []).map(
4343
({ range }) => range,
4444
);
4545
void this.highlights.setHighlightRanges(style, editor, ranges);
46-
});
46+
}
4747
}
4848
}
4949

packages/app-vscode/src/ide/vscode/VscodeToggleBreakpoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function vscodeToggleBreakpoint(
1717
const toAdd: vscode.Breakpoint[] = [];
1818
const toRemove: vscode.Breakpoint[] = [];
1919

20-
ranges.forEach((range) => {
20+
for (const range of ranges) {
2121
const existing = getBreakpoints(uri, range);
2222

2323
if (existing.length > 0) {
@@ -34,7 +34,7 @@ export async function vscodeToggleBreakpoint(
3434
),
3535
);
3636
}
37-
});
37+
}
3838

3939
vscode.debug.addBreakpoints(toAdd);
4040
vscode.debug.removeBreakpoints(toRemove);

packages/app-vscode/src/ide/vscode/hats/VscodeHatRenderer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ export class VscodeHatRenderer {
180180
}
181181

182182
private destroyDecorations() {
183-
Object.values(this.decorationMap).forEach((decoration) => {
183+
for (const decoration of Object.values(this.decorationMap)) {
184184
decoration.dispose();
185-
});
185+
}
186186
}
187187

188188
private async recomputeDecorations() {
@@ -495,7 +495,9 @@ export class VscodeHatRenderer {
495495
dispose() {
496496
this.destroyDecorations();
497497
this.hatsDirWatcherDisposable?.dispose();
498-
this.disposables.forEach(({ dispose }) => dispose());
498+
for (const disposable of this.disposables) {
499+
disposable.dispose();
500+
}
499501
}
500502
}
501503

0 commit comments

Comments
 (0)