Skip to content

Commit 2e477eb

Browse files
authoredApr 14, 2023
[ESLint] replace .forEach with for..of (#3113)
1 parent a8f21ad commit 2e477eb

File tree

26 files changed

+148
-123
lines changed

26 files changed

+148
-123
lines changed
 

‎.changeset/breezy-laws-sneeze.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'codemirror-graphql': patch
3+
'graphiql': patch
4+
'@graphiql/react': patch
5+
'@graphiql/toolkit': patch
6+
'graphql-language-service': patch
7+
'graphql-language-service-server': patch
8+
'monaco-graphql': patch
9+
'vscode-graphql-execution': patch
10+
---
11+
12+
replace `.forEach` with `for..of`

‎.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ module.exports = {
268268
'unicorn/prefer-export-from': ['error', { ignoreUsedVariables: true }],
269269
'unicorn/throw-new-error': 'error',
270270
'unicorn/prefer-includes': 'error',
271+
'unicorn/no-array-for-each': 'error',
271272
'no-lonely-if': 'error',
272273
'unicorn/no-lonely-if': 'error',
273274
'unicorn/prefer-optional-catch-binding': 'error',

‎examples/monaco-graphql-webpack/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,15 @@ function getSchemaPicker(): HTMLSelectElement {
256256
const schemaPicker = document.createElement('select');
257257
schemaPicker.id = 'schema-picker';
258258

259-
schemaOptions.forEach(option => {
259+
for (const option of schemaOptions) {
260260
const optEl = document.createElement('option');
261261
optEl.value = option.value;
262262
optEl.label = option.label;
263263
if (option.default) {
264264
optEl.selected = true;
265265
}
266266
schemaPicker.appendChild(optEl);
267-
});
267+
}
268268

269269
return schemaPicker;
270270
}

‎packages/codemirror-graphql/src/utils/collectVariables.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ export default function collectVariables(
2222
documentAST: DocumentNode,
2323
) {
2424
const variableToType = Object.create(null);
25-
documentAST.definitions.forEach(definition => {
25+
for (const definition of documentAST.definitions) {
2626
if (definition.kind === 'OperationDefinition') {
2727
const { variableDefinitions } = definition;
2828
if (variableDefinitions) {
29-
variableDefinitions.forEach(({ variable, type }) => {
29+
for (const { variable, type } of variableDefinitions) {
3030
const inputType = typeFromAST(schema, type as NamedTypeNode);
3131
if (inputType) {
3232
variableToType[variable.name.value] = inputType;
3333
}
34-
});
34+
}
3535
}
3636
}
37-
});
37+
}
3838
return variableToType;
3939
}

‎packages/codemirror-graphql/src/utils/runParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export default function runParser(
2323
const state = parser.startState();
2424
const lines = sourceText.split('\n');
2525

26-
lines.forEach(line => {
26+
for (const line of lines) {
2727
const stream = new CharacterStream(line);
2828
while (!stream.eol()) {
2929
const style = parser.token(stream, state);
3030
callbackFn(stream, state, style);
3131
}
32-
});
32+
}
3333
}

‎packages/codemirror-graphql/src/variables/lint.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ function validateVariables(
8585
) {
8686
const errors: CodeMirror.Annotation[] = [];
8787

88-
variablesAST.members.forEach(member => {
88+
for (const member of variablesAST.members) {
8989
if (member) {
9090
const variableName = member.key?.value;
9191
const type = variableToType[variableName];
9292
if (type) {
93-
validateValue(type, member.value).forEach(([node, message]) => {
93+
for (const [node, message] of validateValue(type, member.value)) {
9494
errors.push(lintError(editor, node, message));
95-
});
95+
}
9696
} else {
9797
errors.push(
9898
lintError(
@@ -103,7 +103,7 @@ function validateVariables(
103103
);
104104
}
105105
}
106-
});
106+
}
107107

108108
return errors;
109109
}
@@ -169,7 +169,7 @@ function validateValue(
169169
);
170170

171171
// Look for missing non-nullable fields.
172-
Object.keys(type.getFields()).forEach(fieldName => {
172+
for (const fieldName of Object.keys(type.getFields())) {
173173
const field = type.getFields()[fieldName];
174174
if (
175175
!providedFields[fieldName] &&
@@ -181,7 +181,7 @@ function validateValue(
181181
`Object of type "${type}" is missing required field "${fieldName}".`,
182182
]);
183183
}
184-
});
184+
}
185185

186186
return fieldErrors;
187187
}

‎packages/graphiql-react/src/editor/hooks.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,17 @@ export function useAutoCompleteLeafs({
314314
},
315315
),
316316
);
317-
setTimeout(() => markers.forEach(marker => marker.clear()), 7000);
317+
setTimeout(() => {
318+
for (const marker of markers) {
319+
marker.clear();
320+
}
321+
}, 7000);
318322
let newCursorIndex = cursorIndex;
319-
insertions.forEach(({ index, string }) => {
323+
for (const { index, string } of insertions) {
320324
if (index < cursorIndex) {
321325
newCursorIndex += string.length;
322326
}
323-
});
327+
}
324328
queryEditor.setCursor(queryEditor.posFromIndex(newCursorIndex));
325329
});
326330
}

‎packages/graphiql-toolkit/src/graphql-helpers/auto-complete.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ function defaultGetDefaultFieldNames(type: GraphQLType) {
109109

110110
// Include all leaf-type fields.
111111
const leafFieldNames: Array<string> = [];
112-
Object.keys(fields).forEach(fieldName => {
112+
for (const fieldName of Object.keys(fields)) {
113113
if (isLeafType(fields[fieldName].type)) {
114114
leafFieldNames.push(fieldName);
115115
}
116-
});
116+
}
117117
return leafFieldNames;
118118
}
119119

@@ -174,10 +174,10 @@ function withInsertions(initial: string, insertions: Insertion[]) {
174174
}
175175
let edited = '';
176176
let prevIndex = 0;
177-
insertions.forEach(({ index, string }) => {
177+
for (const { index, string } of insertions) {
178178
edited += initial.slice(prevIndex, index) + string;
179179
prevIndex = index;
180-
});
180+
}
181181
edited += initial.slice(prevIndex);
182182
return edited;
183183
}

‎packages/graphiql/cypress/e2e/init.cy.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ describe('GraphiQL On Initialization', () => {
3838
];
3939
cy.visit(`/`);
4040
cy.get('.graphiql-query-editor').contains('# Welcome to GraphiQL');
41-
containers.forEach(cSelector => cy.get(cSelector).should('be.visible'));
41+
for (const cSelector of containers) {
42+
cy.get(cSelector).should('be.visible');
43+
}
4244
});
4345

4446
it('Executes a GraphQL query over HTTP that has the expected result', () => {

‎packages/graphiql/resources/renderExample.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414

1515
// Parse the search string to get url parameters.
1616
var parameters = {};
17-
window.location.search
18-
.slice(1)
19-
.split('&')
20-
.forEach(function (entry) {
21-
var eq = entry.indexOf('=');
22-
if (eq >= 0) {
23-
parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent(
24-
entry.slice(eq + 1),
25-
);
26-
}
27-
});
17+
for (const entry of window.location.search.slice(1).split('&')) {
18+
var eq = entry.indexOf('=');
19+
if (eq >= 0) {
20+
parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent(
21+
entry.slice(eq + 1),
22+
);
23+
}
24+
}
2825

2926
// When the query and variables string is edited, update the URL bar so
3027
// that it can be easily shared.

‎packages/graphql-language-service-server/src/GraphQLCache.ts

+38-36
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,15 @@ export class GraphQLCache implements GraphQLCacheInterface {
151151
});
152152

153153
const asts = new Set<FragmentInfo>();
154-
referencedFragNames.forEach(name => {
154+
for (const name of referencedFragNames) {
155155
if (!existingFrags.has(name) && fragmentDefinitions.has(name)) {
156156
asts.add(nullthrows(fragmentDefinitions.get(name)));
157157
}
158-
});
158+
}
159159

160160
const referencedFragments: FragmentInfo[] = [];
161161

162-
asts.forEach(ast => {
162+
for (const ast of asts) {
163163
visit(ast.definition, {
164164
FragmentSpread(node) {
165165
if (
@@ -174,7 +174,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
174174
if (!existingFrags.has(ast.definition.name.value)) {
175175
referencedFragments.push(ast);
176176
}
177-
});
177+
}
178178

179179
return referencedFragments;
180180
};
@@ -252,15 +252,15 @@ export class GraphQLCache implements GraphQLCacheInterface {
252252
});
253253

254254
const asts = new Set<ObjectTypeInfo>();
255-
referencedObjectTypes.forEach(name => {
255+
for (const name of referencedObjectTypes) {
256256
if (!existingObjectTypes.has(name) && objectTypeDefinitions.has(name)) {
257257
asts.add(nullthrows(objectTypeDefinitions.get(name)));
258258
}
259-
});
259+
}
260260

261261
const referencedObjects: ObjectTypeInfo[] = [];
262262

263-
asts.forEach(ast => {
263+
for (const ast of asts) {
264264
visit(ast.definition, {
265265
NamedType(node) {
266266
if (
@@ -275,7 +275,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
275275
if (!existingObjectTypes.has(ast.definition.name.value)) {
276276
referencedObjects.push(ast);
277277
}
278-
});
278+
}
279279

280280
return referencedObjects;
281281
};
@@ -412,25 +412,25 @@ export class GraphQLCache implements GraphQLCacheInterface {
412412
});
413413
if (cache) {
414414
// first go through the fragment list to delete the ones from this file
415-
cache.forEach((value, key) => {
415+
for (const [key, value] of cache.entries()) {
416416
if (value.filePath === filePath) {
417417
cache.delete(key);
418418
}
419-
});
420-
asts.forEach(({ ast, query }) => {
419+
}
420+
for (const { ast, query } of asts) {
421421
if (!ast) {
422-
return;
422+
continue;
423423
}
424-
ast.definitions.forEach(definition => {
424+
for (const definition of ast.definitions) {
425425
if (definition.kind === Kind.FRAGMENT_DEFINITION) {
426426
cache.set(definition.name.value, {
427427
filePath,
428428
content: query,
429429
definition,
430430
});
431431
}
432-
});
433-
});
432+
}
433+
}
434434
}
435435
}
436436

@@ -474,16 +474,16 @@ export class GraphQLCache implements GraphQLCacheInterface {
474474
});
475475
if (cache) {
476476
// first go through the types list to delete the ones from this file
477-
cache.forEach((value, key) => {
477+
for (const [key, value] of cache.entries()) {
478478
if (value.filePath === filePath) {
479479
cache.delete(key);
480480
}
481-
});
482-
asts.forEach(({ ast, query }) => {
481+
}
482+
for (const { ast, query } of asts) {
483483
if (!ast) {
484-
return;
484+
continue;
485485
}
486-
ast.definitions.forEach(definition => {
486+
for (const definition of ast.definitions) {
487487
if (
488488
definition.kind === Kind.OBJECT_TYPE_DEFINITION ||
489489
definition.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ||
@@ -495,8 +495,8 @@ export class GraphQLCache implements GraphQLCacheInterface {
495495
definition,
496496
});
497497
}
498-
});
499-
});
498+
}
499+
}
500500
}
501501
}
502502

@@ -537,12 +537,12 @@ export class GraphQLCache implements GraphQLCacheInterface {
537537
if (!graphQLFileMap) {
538538
return schema;
539539
}
540-
graphQLFileMap.forEach(({ filePath, asts }) => {
541-
asts.forEach(ast => {
540+
for (const { filePath, asts } of graphQLFileMap.values()) {
541+
for (const ast of asts) {
542542
if (filePath === schemaPath) {
543-
return;
543+
continue;
544544
}
545-
ast.definitions.forEach(definition => {
545+
for (const definition of ast.definitions) {
546546
switch (definition.kind) {
547547
case Kind.OBJECT_TYPE_DEFINITION:
548548
case Kind.INTERFACE_TYPE_DEFINITION:
@@ -560,9 +560,9 @@ export class GraphQLCache implements GraphQLCacheInterface {
560560
typeExtensions.push(definition);
561561
break;
562562
}
563-
});
564-
});
565-
});
563+
}
564+
}
565+
}
566566

567567
if (schemaCacheKey) {
568568
const sorted = typeExtensions.sort((a: any, b: any) => {
@@ -723,12 +723,12 @@ export class GraphQLCache implements GraphQLCacheInterface {
723723
const fragmentDefinitions = new Map();
724724
const graphQLFileMap = new Map();
725725

726-
responses.forEach(response => {
726+
for (const response of responses) {
727727
const { filePath, content, asts, mtime, size } = response;
728728

729729
if (asts) {
730-
asts.forEach(ast => {
731-
ast.definitions.forEach(definition => {
730+
for (const ast of asts) {
731+
for (const definition of ast.definitions) {
732732
if (definition.kind === Kind.FRAGMENT_DEFINITION) {
733733
fragmentDefinitions.set(definition.name.value, {
734734
filePath,
@@ -747,8 +747,8 @@ export class GraphQLCache implements GraphQLCacheInterface {
747747
definition,
748748
});
749749
}
750-
});
751-
});
750+
}
751+
}
752752
}
753753

754754
// Relay the previous object whether or not ast exists.
@@ -759,7 +759,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
759759
mtime,
760760
size,
761761
});
762-
});
762+
}
763763

764764
return {
765765
objectTypeDefinitions,
@@ -794,7 +794,9 @@ export class GraphQLCache implements GraphQLCacheInterface {
794794
};
795795
}
796796

797-
queries.forEach(({ query }) => asts.push(parse(query)));
797+
for (const { query } of queries) {
798+
asts.push(parse(query));
799+
}
798800
return {
799801
filePath,
800802
content,

‎packages/graphql-language-service-server/src/findGraphQLTags.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ function traverse(node: { [key: string]: any }, visitors: TagVisitors) {
293293
if (prop && typeof prop === 'object' && typeof prop.type === 'string') {
294294
visit(prop, visitors);
295295
} else if (Array.isArray(prop)) {
296-
prop.forEach(item => {
296+
for (const item of prop) {
297297
if (item && typeof item === 'object' && typeof item.type === 'string') {
298298
visit(item, visitors);
299299
}
300-
});
300+
}
301301
}
302302
}
303303
}

‎packages/graphql-language-service/benchmark/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const runSplitTest = (name: string, schema: string) => {
3030
const parser = onlineParser();
3131
let state: any = parser.startState();
3232

33-
schema.split('\n').forEach((line, index) => {
33+
for (const [index, line] of schema.split('\n').entries()) {
3434
let prevState: any;
3535
let completeState: any;
3636

@@ -59,7 +59,7 @@ const runSplitTest = (name: string, schema: string) => {
5959
stats.push(e.target.stats);
6060
},
6161
});
62-
});
62+
}
6363

6464
console.log(`Started test suite: ${name}`);
6565

‎packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,11 @@ function getSuggestionsForFragmentTypeConditions(
746746
// they implement.
747747
const possibleObjTypes = schema.getPossibleTypes(abstractType);
748748
const possibleIfaceMap = Object.create(null);
749-
possibleObjTypes.forEach(type => {
750-
type.getInterfaces().forEach(iface => {
749+
for (const type of possibleObjTypes) {
750+
for (const iface of type.getInterfaces()) {
751751
possibleIfaceMap[iface.name] = iface;
752-
});
753-
});
752+
}
753+
}
754754
possibleTypes = possibleObjTypes.concat(objectValues(possibleIfaceMap));
755755
} else {
756756
// The parent type is a non-abstract Object type, so the only possible

‎packages/graphql-language-service/src/interface/getDefinition.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ export async function getDefinitionQueryResultForField(
8787

8888
const definitions: Array<Definition> = [];
8989

90-
defNodes.forEach(({ filePath, content, definition }) => {
90+
for (const { filePath, content, definition } of defNodes) {
9191
const fieldDefinition = (
9292
definition as ObjectTypeDefinitionNode
9393
).fields?.find(item => item.name.value === fieldName);
9494

9595
if (fieldDefinition == null) {
96-
return null;
96+
continue;
9797
}
9898

9999
definitions.push(
100100
getDefinitionForFieldDefinition(filePath || '', content, fieldDefinition),
101101
);
102-
});
102+
}
103103

104104
return {
105105
definitions,

‎packages/graphql-language-service/src/interface/getDiagnostics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function annotations(
138138
return [];
139139
}
140140
const highlightedNodes: Diagnostic[] = [];
141-
error.nodes.forEach((node, i) => {
141+
for (const [i, node] of error.nodes.entries()) {
142142
const highlightNode =
143143
node.kind !== 'Variable' && 'name' in node && node.name !== undefined
144144
? node.name
@@ -166,7 +166,7 @@ function annotations(
166166
),
167167
});
168168
}
169-
});
169+
}
170170
return highlightedNodes;
171171
}
172172

‎packages/graphql-language-service/src/parser/__tests__/OnlineParserUtils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ export const expectVarsDef = (
142142
) => {
143143
t.punctuation(/\(/, { kind: 'VariableDefinitions' });
144144

145-
vars.forEach(variable => {
145+
for (const variable of vars) {
146146
t.variable('$', { kind: 'Variable' });
147147
t.variable(variable.name);
148148
t.punctuation(':', { kind: 'VariableDefinition' });
149149
t.name(variable.type, { kind: 'NamedType' });
150150

151151
stream.eatWhile(/(,|\s)/);
152-
});
152+
}
153153

154154
t.punctuation(/\)/, { kind: onKind });
155155
};
@@ -160,7 +160,7 @@ export const expectArgs = (
160160
) => {
161161
t.punctuation(/\(/, { kind: 'Arguments' });
162162

163-
args.forEach(arg => {
163+
for (const arg of args) {
164164
t.attribute(arg.name, { kind: 'Argument' });
165165
t.punctuation(':');
166166
if (arg.isVariable) {
@@ -177,7 +177,7 @@ export const expectArgs = (
177177
}
178178

179179
stream.eatWhile(/(,|\s)/);
180-
});
180+
}
181181

182182
t.punctuation(/\)/, { kind: onKind });
183183
};

‎packages/graphql-language-service/src/utils/collectVariables.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export function collectVariables(
2626
): VariableToType {
2727
const variableToType: VariableToType = Object.create(null);
2828
// it would be more ideal to use visitWithTypeInfo here but it's very simple
29-
documentAST.definitions.forEach(definition => {
29+
for (const definition of documentAST.definitions) {
3030
if (definition.kind === 'OperationDefinition') {
3131
const { variableDefinitions } = definition;
3232
if (variableDefinitions) {
33-
variableDefinitions.forEach(({ variable, type }) => {
33+
for (const { variable, type } of variableDefinitions) {
3434
const inputType = typeFromAST(
3535
schema,
3636
type as NamedTypeNode,
@@ -44,9 +44,9 @@ export function collectVariables(
4444
) {
4545
variableToType[variable.name.value] = GraphQLFloat;
4646
}
47-
});
47+
}
4848
}
4949
}
50-
});
50+
}
5151
return variableToType;
5252
}

‎packages/graphql-language-service/src/utils/fragmentDependencies.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ export const getFragmentDependenciesForAST = (
5151
});
5252

5353
const asts = new Set<FragmentDefinitionNode>();
54-
referencedFragNames.forEach(name => {
54+
for (const name of referencedFragNames) {
5555
if (!existingFrags.has(name) && fragmentDefinitions.has(name)) {
5656
asts.add(nullthrows(fragmentDefinitions.get(name)));
5757
}
58-
});
58+
}
5959

6060
const referencedFragments: FragmentDefinitionNode[] = [];
6161

62-
asts.forEach(ast => {
62+
for (const ast of asts) {
6363
visit(ast, {
6464
FragmentSpread(node) {
6565
if (
@@ -74,7 +74,7 @@ export const getFragmentDependenciesForAST = (
7474
if (!existingFrags.has(ast.name.value)) {
7575
referencedFragments.push(ast);
7676
}
77-
});
77+
}
7878

7979
return referencedFragments;
8080
};

‎packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ function getJSONSchemaFromGraphQLType(
158158
definition.items = def;
159159
}
160160
if (defs) {
161-
Object.keys(defs).forEach(defName => {
161+
for (const defName of Object.keys(defs)) {
162162
definitions[defName] = defs[defName];
163-
});
163+
}
164164
}
165165
}
166166
if (isNonNullType(type)) {
@@ -171,9 +171,9 @@ function getJSONSchemaFromGraphQLType(
171171
);
172172
definition = def;
173173
if (defs) {
174-
Object.keys(defs).forEach(defName => {
174+
for (const defName of Object.keys(defs)) {
175175
definitions[defName] = defs[defName];
176-
});
176+
}
177177
}
178178
}
179179
if (isInputObjectType(type)) {
@@ -202,7 +202,7 @@ function getJSONSchemaFromGraphQLType(
202202
}
203203
}
204204

205-
Object.keys(fields).forEach(fieldName => {
205+
for (const fieldName of Object.keys(fields)) {
206206
const field = fields[fieldName];
207207
const {
208208
required: fieldRequired,
@@ -242,7 +242,7 @@ function getJSONSchemaFromGraphQLType(
242242
definitions[defName] = typeDefinitions[defName];
243243
});
244244
}
245-
});
245+
}
246246
definitions[type.name] = fieldDef;
247247
}
248248
}
@@ -324,7 +324,7 @@ export function getVariablesJSONSchema(
324324

325325
if (variableToType) {
326326
// I would use a reduce here, but I wanted it to be readable.
327-
Object.entries(variableToType).forEach(([variableName, type]) => {
327+
for (const [variableName, type] of Object.entries(variableToType)) {
328328
const { definition, required, definitions } =
329329
getJSONSchemaFromGraphQLType(type, runtimeOptions);
330330
jsonSchema.properties[variableName] = definition;
@@ -334,7 +334,7 @@ export function getVariablesJSONSchema(
334334
if (definitions) {
335335
jsonSchema.definitions = { ...jsonSchema?.definitions, ...definitions };
336336
}
337-
});
337+
}
338338
}
339339
return jsonSchema;
340340
}

‎packages/monaco-graphql/src/LanguageService.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export class LanguageService {
8585
}
8686

8787
private _cacheSchemas() {
88-
this._schemas.forEach(schema => this._cacheSchema(schema));
88+
for (const schema of this._schemas) {
89+
this._cacheSchema(schema);
90+
}
8991
}
9092

9193
private _cacheSchema(schemaConfig: SchemaConfig) {

‎packages/monaco-graphql/src/languageFeatures.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,24 @@ export class DiagnosticsAdapter {
9494
},
9595
},
9696
defaults.onDidChange(() => {
97-
editor.getModels().forEach(model => {
97+
for (const model of editor.getModels()) {
9898
if (getModelLanguageId(model) === this.defaults.languageId) {
9999
onModelRemoved(model);
100100
onModelAdd(model);
101101
}
102-
});
102+
}
103103
}),
104104
);
105105

106-
editor.getModels().forEach(onModelAdd);
106+
for (const model of editor.getModels()) {
107+
onModelAdd(model);
108+
}
107109
}
108110

109111
public dispose(): void {
110-
this._disposables.forEach(d => d?.dispose());
112+
for (const d of this._disposables) {
113+
d?.dispose();
114+
}
111115
this._disposables = [];
112116
}
113117

‎packages/vscode-graphql-execution/src/helpers/network.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ export class NetworkHelper {
128128
fragmentDefinitions,
129129
);
130130

131-
fragmentInfos.forEach(fragmentInfo => {
131+
for (const fragmentInfo of fragmentInfos) {
132132
literal.content = fragmentInfo.content + '\n' + literal.content;
133-
});
133+
}
134134

135135
const parsedOperation = gql`
136136
${literal.content}

‎packages/vscode-graphql-execution/src/helpers/source.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class SourceHelper {
127127
const sources = await projectConfig.getDocuments();
128128
const { fragmentDefinitions } = this;
129129

130-
sources.forEach(source => {
130+
for (const source of sources) {
131131
visit(source.document as DocumentNode, {
132132
FragmentDefinition(node) {
133133
const existingDef = fragmentDefinitions.get(node.name.value);
@@ -141,7 +141,7 @@ export class SourceHelper {
141141
}
142142
},
143143
});
144-
});
144+
}
145145
return fragmentDefinitions;
146146
}
147147

@@ -160,7 +160,7 @@ export class SourceHelper {
160160
} catch {}
161161
}
162162

163-
tags.forEach(tag => {
163+
for (const tag of tags) {
164164
// https://regex101.com/r/Pd5PaU/2
165165
const regExpGQL = new RegExp(tag + '\\s*`([\\s\\S]+?)`', 'mg');
166166

@@ -179,15 +179,16 @@ export class SourceHelper {
179179
// don't break the extension while editing
180180
} catch {}
181181
}
182-
});
182+
}
183183
return documents;
184184

185185
function processGraphQLString(textString: string, offset: number) {
186186
const ast = parse(textString);
187187
const operations = ast.definitions.filter(
188188
def => def.kind === 'OperationDefinition',
189189
);
190-
operations.forEach((op: any) => {
190+
for (const operation of operations) {
191+
const op = operation as any;
191192
const filteredAst = {
192193
...ast,
193194
definitions: ast.definitions.filter(def => {
@@ -204,7 +205,7 @@ export class SourceHelper {
204205
definition: op,
205206
ast: filteredAst,
206207
});
207-
});
208+
}
208209
// no-op, so that non-parse-able source files
209210
// don't break the extension while editing
210211
}
@@ -265,15 +266,15 @@ export const getFragmentDependenciesForAST = async (
265266
});
266267

267268
const asts = new Set<FragmentInfo>();
268-
referencedFragNames.forEach(name => {
269+
for (const name of referencedFragNames) {
269270
if (!existingFrags.has(name) && fragmentDefinitions.has(name)) {
270271
asts.add(nullthrows(fragmentDefinitions.get(name)));
271272
}
272-
});
273+
}
273274

274275
const referencedFragments: FragmentInfo[] = [];
275276

276-
asts.forEach(ast => {
277+
for (const ast of asts) {
277278
visit(ast.definition, {
278279
FragmentSpread(node) {
279280
if (
@@ -288,7 +289,7 @@ export const getFragmentDependenciesForAST = async (
288289
if (!existingFrags.has(ast.definition.name.value)) {
289290
referencedFragments.push(ast);
290291
}
291-
});
292+
}
292293

293294
return referencedFragments;
294295
};

‎scripts/buildFlow.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const { join } = require('node:path');
1313
const { cp } = require('./util');
1414

1515
// Non-recursively copy src/*.js to dist/*.js.flow:
16-
readdirSync('src').forEach(entry => {
16+
for (const entry of readdirSync('src')) {
1717
if (entry.endsWith('.js')) {
1818
const source = join('src', entry);
1919
const destination = join(process.argv[2] || 'dist', `${entry}.flow`);
2020
cp(source, destination);
2121
}
22-
});
22+
}

‎scripts/renameFileExtensions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (tempPath) {
3232
if (error) {
3333
throw error;
3434
}
35-
files.forEach(file => {
35+
for (const file of files) {
3636
if (file.dest) {
3737
const srcExt = path.parse(file.dest).ext;
3838
const destinationPath = path.resolve(
@@ -45,7 +45,7 @@ if (tempPath) {
4545
// move the files and rename them... by renaming them :)
4646
fs.renameSync(file.dest, destinationPath);
4747
}
48-
});
48+
}
4949
// should cleanup temp directory after renaming
5050
// every file to the destination path
5151
rimraf.sync(tempRenamePath);

0 commit comments

Comments
 (0)
Please sign in to comment.