Skip to content

Commit 5b56467

Browse files
authored
chore: use for..of instead of forEach (#14517)
1 parent c985cb4 commit 5b56467

File tree

110 files changed

+696
-691
lines changed

Some content is hidden

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

110 files changed

+696
-691
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ module.exports = {
595595
yoda: 'off',
596596

597597
'unicorn/explicit-length-check': 'error',
598+
'unicorn/no-array-for-each': 'error',
598599
'unicorn/no-negated-condition': 'error',
599600
'unicorn/prefer-default-parameters': 'error',
600601
'unicorn/prefer-includes': 'error',

e2e/MockStdinWatchPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MockStdinWatchPlugin {
2020
apply(jestHooks) {
2121
jestHooks.onTestRunComplete(() => {
2222
const {keys} = this._config.input.shift();
23-
keys.forEach(key => this._stdin.emit('data', key));
23+
for (const key of keys) this._stdin.emit('data', key);
2424
});
2525
}
2626
}

e2e/Utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export const writeFiles = (
128128
files: {[filename: string]: string},
129129
) => {
130130
fs.mkdirSync(directory, {recursive: true});
131-
Object.keys(files).forEach(fileOrPath => {
131+
for (const fileOrPath of Object.keys(files)) {
132132
const dirname = path.dirname(fileOrPath);
133133

134134
if (dirname !== '/') {
@@ -138,15 +138,15 @@ export const writeFiles = (
138138
path.resolve(directory, ...fileOrPath.split('/')),
139139
dedent(files[fileOrPath]),
140140
);
141-
});
141+
}
142142
};
143143

144144
export const writeSymlinks = (
145145
directory: string,
146146
symlinks: {[existingFile: string]: string},
147147
) => {
148148
fs.mkdirSync(directory, {recursive: true});
149-
Object.keys(symlinks).forEach(fileOrPath => {
149+
for (const fileOrPath of Object.keys(symlinks)) {
150150
const symLinkPath = symlinks[fileOrPath];
151151
const dirname = path.dirname(symLinkPath);
152152

@@ -158,7 +158,7 @@ export const writeSymlinks = (
158158
path.resolve(directory, ...symLinkPath.split('/')),
159159
'junction',
160160
);
161-
});
161+
}
162162
};
163163

164164
const NUMBER_OF_TESTS_TO_FORCE_USING_WORKERS = 25;

e2e/__tests__/coverageRemapping.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ it('maps code coverage against original source', () => {
2727
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
2828

2929
// reduce absolute paths embedded in the coverage map to just filenames
30-
Object.keys(coverageMap).forEach(filename => {
30+
for (const filename of Object.keys(coverageMap)) {
3131
coverageMap[filename].path = path.basename(coverageMap[filename].path);
3232
delete coverageMap[filename].hash;
3333
coverageMap[path.basename(filename)] = coverageMap[filename];
3434
delete coverageMap[filename];
35-
});
35+
}
3636
expect(coverageMap).toMatchSnapshot();
3737
});

e2e/__tests__/coverageTransformInstrumented.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ it('code coverage for transform instrumented code', () => {
2727
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
2828

2929
// reduce absolute paths embedded in the coverage map to just filenames
30-
Object.keys(coverageMap).forEach(filename => {
30+
for (const filename of Object.keys(coverageMap)) {
3131
coverageMap[filename].path = path.basename(coverageMap[filename].path);
3232
delete coverageMap[filename].hash;
3333
coverageMap[path.basename(filename)] = coverageMap[filename];
3434
delete coverageMap[filename];
35-
});
35+
}
3636
expect(coverageMap).toMatchSnapshot();
3737
});

e2e/__tests__/errorOnDeprecated.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const SHOULD_NOT_PASS_IN_JEST = new Set([
3131
'spyOnProperty.test.js',
3232
]);
3333

34-
testFiles.forEach(testFile => {
34+
for (const testFile of testFiles) {
3535
test(`${testFile} errors in errorOnDeprecated mode`, () => {
3636
const result = runJest('error-on-deprecated', [
3737
testFile,
@@ -42,9 +42,9 @@ testFiles.forEach(testFile => {
4242

4343
expect(rest).toMatchSnapshot();
4444
});
45-
});
45+
}
4646

47-
testFiles.forEach(testFile => {
47+
for (const testFile of testFiles) {
4848
const shouldPass = SHOULD_NOT_PASS_IN_JEST.has(testFile);
4949

5050
const expectation = `${testFile} ${shouldPass ? 'errors' : 'passes'}`;
@@ -54,4 +54,4 @@ testFiles.forEach(testFile => {
5454
const result = runJest('error-on-deprecated', [testFile]);
5555
expect(result.exitCode).toBe(shouldPass ? 1 : 0);
5656
});
57-
});
57+
}

e2e/__tests__/snapshot.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ const getSnapshotOfCopy = () => {
7070

7171
describe('Snapshot', () => {
7272
const cleanup = () => {
73-
[
73+
for (const file of [
7474
snapshotFile,
7575
secondSnapshotFile,
7676
snapshotOfCopy,
7777
copyOfTestPath,
7878
snapshotEscapeFile,
7979
snapshotEscapeRegexFile,
8080
snapshotEscapeSubstitutionFile,
81-
].forEach(file => {
81+
]) {
8282
if (fileExists(file)) {
8383
fs.unlinkSync(file);
8484
}
85-
});
85+
}
8686
if (fileExists(snapshotDir)) {
8787
fs.rmdirSync(snapshotDir);
8888
}

e2e/__tests__/summaryThreshold.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import runJest from '../runJest';
99

10-
['default', 'summary'].forEach(reporter => {
10+
for (const reporter of ['default', 'summary']) {
1111
describe(`${reporter} reporter`, () => {
1212
test('prints failure messages when total number of test suites is over summaryThreshold', () => {
1313
const {exitCode, stderr} = runJest('summary-threshold', [
@@ -26,4 +26,4 @@ import runJest from '../runJest';
2626
);
2727
});
2828
});
29-
});
29+
}

e2e/__tests__/transform.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ describe('transformer caching', () => {
199199
const loggedFiles = stdout.split('\n');
200200

201201
// Verify any lines logged are _just_ the file we care about
202-
loggedFiles.forEach(line => {
202+
for (const line of loggedFiles) {
203203
expect(line).toBe(transformedFile);
204-
});
204+
}
205205

206206
// We run with 2 workers, so the file should be transformed twice
207207
expect(loggedFiles).toHaveLength(2);

e2e/__tests__/watchModeOnlyFailed.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ test('can press "f" to run only failed tests', () => {
4141
const results = extractSummaries(stderr);
4242

4343
expect(results).toHaveLength(2);
44-
results.forEach(({rest, summary}) => {
44+
for (const {rest, summary} of results) {
4545
expect(rest).toMatchSnapshot('test results');
4646
expect(summary).toMatchSnapshot('test summary');
47-
});
47+
}
4848
expect(exitCode).toBe(0);
4949
});

0 commit comments

Comments
 (0)