diff --git a/src/jsutils/suggestionList.js b/src/jsutils/suggestionList.js index 88ef53f092..7e6bcbeb4a 100644 --- a/src/jsutils/suggestionList.js +++ b/src/jsutils/suggestionList.js @@ -16,13 +16,12 @@ export default function suggestionList( options: $ReadOnlyArray, ): Array { const optionsByDistance = Object.create(null); - const oLength = options.length; const inputThreshold = input.length / 2; - for (let i = 0; i < oLength; i++) { - const distance = lexicalDistance(input, options[i]); - const threshold = Math.max(inputThreshold, options[i].length / 2, 1); + for (const option of options) { + const distance = lexicalDistance(input, option); + const threshold = Math.max(inputThreshold, option.length / 2, 1); if (distance <= threshold) { - optionsByDistance[options[i]] = distance; + optionsByDistance[option] = distance; } } return Object.keys(optionsByDistance).sort( diff --git a/src/utilities/astFromValue.js b/src/utilities/astFromValue.js index 0ba2f323fc..dd805141d2 100644 --- a/src/utilities/astFromValue.js +++ b/src/utilities/astFromValue.js @@ -84,9 +84,8 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode { if (value === null || typeof value !== 'object') { return null; } - const fields = objectValues(type.getFields()); const fieldNodes = []; - for (const field of fields) { + for (const field of objectValues(type.getFields())) { const fieldValue = astFromValue(value[field.name], field.type); if (fieldValue) { fieldNodes.push({ diff --git a/src/utilities/getOperationAST.js b/src/utilities/getOperationAST.js index 6c09e17b37..2e8dacf0ee 100644 --- a/src/utilities/getOperationAST.js +++ b/src/utilities/getOperationAST.js @@ -23,8 +23,7 @@ export function getOperationAST( operationName: ?string, ): ?OperationDefinitionNode { let operation = null; - for (let i = 0; i < documentAST.definitions.length; i++) { - const definition = documentAST.definitions[i]; + for (const definition of documentAST.definitions) { if (definition.kind === Kind.OPERATION_DEFINITION) { if (!operationName) { // If no operation name was provided, only return an Operation if there diff --git a/src/utilities/schemaPrinter.js b/src/utilities/schemaPrinter.js index 792c692fb3..965e9bb192 100644 --- a/src/utilities/schemaPrinter.js +++ b/src/utilities/schemaPrinter.js @@ -339,11 +339,11 @@ function printDescription( function printDescriptionWithComments(lines, indentation, firstInBlock) { let description = indentation && !firstInBlock ? '\n' : ''; - for (let i = 0; i < lines.length; i++) { - if (lines[i] === '') { + for (const line of lines) { + if (line === '') { description += indentation + '#\n'; } else { - description += indentation + '# ' + lines[i] + '\n'; + description += indentation + '# ' + line + '\n'; } } return description; diff --git a/src/utilities/valueFromAST.js b/src/utilities/valueFromAST.js index 6b797f9eca..40f3c58d24 100644 --- a/src/utilities/valueFromAST.js +++ b/src/utilities/valueFromAST.js @@ -86,9 +86,8 @@ export function valueFromAST( const itemType = type.ofType; if (valueNode.kind === Kind.LIST) { const coercedValues = []; - const itemNodes = valueNode.values; - for (let i = 0; i < itemNodes.length; i++) { - if (isMissingVariable(itemNodes[i], variables)) { + for (const itemNode of valueNode.values) { + if (isMissingVariable(itemNode, variables)) { // If an array contains a missing variable, it is either coerced to // null or if the item type is non-null, it considered invalid. if (isNonNullType(itemType)) { @@ -96,7 +95,7 @@ export function valueFromAST( } coercedValues.push(null); } else { - const itemValue = valueFromAST(itemNodes[i], itemType, variables); + const itemValue = valueFromAST(itemNode, itemType, variables); if (isInvalid(itemValue)) { return; // Invalid: intentionally return no value. } @@ -118,9 +117,7 @@ export function valueFromAST( } const coercedObj = Object.create(null); const fieldNodes = keyMap(valueNode.fields, field => field.name.value); - const fields = objectValues(type.getFields()); - for (let i = 0; i < fields.length; i++) { - const field = fields[i]; + for (const field of objectValues(type.getFields())) { const fieldNode = fieldNodes[field.name]; if (!fieldNode || isMissingVariable(fieldNode.value, variables)) { if (field.defaultValue !== undefined) { diff --git a/src/validation/ValidationContext.js b/src/validation/ValidationContext.js index 9bdc6ae572..baed70b4c2 100644 --- a/src/validation/ValidationContext.js +++ b/src/validation/ValidationContext.js @@ -97,8 +97,7 @@ export class ASTValidationContext { const setsToVisit: Array = [node]; while (setsToVisit.length !== 0) { const set = setsToVisit.pop(); - for (let i = 0; i < set.selections.length; i++) { - const selection = set.selections[i]; + for (const selection of set.selections) { if (selection.kind === Kind.FRAGMENT_SPREAD) { spreads.push(selection); } else if (selection.selectionSet) { @@ -121,9 +120,8 @@ export class ASTValidationContext { const nodesToVisit: Array = [operation.selectionSet]; while (nodesToVisit.length !== 0) { const node = nodesToVisit.pop(); - const spreads = this.getFragmentSpreads(node); - for (let i = 0; i < spreads.length; i++) { - const fragName = spreads[i].name.value; + for (const spread of this.getFragmentSpreads(node)) { + const fragName = spread.name.value; if (collectedNames[fragName] !== true) { collectedNames[fragName] = true; const fragment = this.getFragment(fragName); @@ -212,12 +210,8 @@ export class ValidationContext extends ASTValidationContext { let usages = this._recursiveVariableUsages.get(operation); if (!usages) { usages = this.getVariableUsages(operation); - const fragments = this.getRecursivelyReferencedFragments(operation); - for (let i = 0; i < fragments.length; i++) { - Array.prototype.push.apply( - usages, - this.getVariableUsages(fragments[i]), - ); + for (const frag of this.getRecursivelyReferencedFragments(operation)) { + usages = usages.concat(this.getVariableUsages(frag)); } this._recursiveVariableUsages.set(operation, usages); } diff --git a/src/validation/rules/NoFragmentCycles.js b/src/validation/rules/NoFragmentCycles.js index 993a82253d..a9234a42aa 100644 --- a/src/validation/rules/NoFragmentCycles.js +++ b/src/validation/rules/NoFragmentCycles.js @@ -57,8 +57,7 @@ export function NoFragmentCycles(context: ASTValidationContext): ASTVisitor { spreadPathIndexByName[fragmentName] = spreadPath.length; - for (let i = 0; i < spreadNodes.length; i++) { - const spreadNode = spreadNodes[i]; + for (const spreadNode of spreadNodes) { const spreadName = spreadNode.name.value; const cycleIndex = spreadPathIndexByName[spreadName];