diff --git a/src/jsutils/inspect.js b/src/jsutils/inspect.js index 03cc2d7b5f..b4cebc4a8a 100644 --- a/src/jsutils/inspect.js +++ b/src/jsutils/inspect.js @@ -31,7 +31,7 @@ function formatObjectValue( return 'null'; } - if (previouslySeenValues.indexOf(value) !== -1) { + if (previouslySeenValues.includes(value)) { return '[Circular]'; } diff --git a/src/language/blockString.js b/src/language/blockString.js index 08f106005e..013cb60011 100644 --- a/src/language/blockString.js +++ b/src/language/blockString.js @@ -95,7 +95,7 @@ export function printBlockString( value: string, preferMultipleLines: boolean = false, ): string { - const isSingleLine = value.indexOf('\n') === -1; + const isSingleLine = !value.includes('\n'); const hasLeadingSpace = value[0] === ' ' || value[0] === '\t'; const hasTrailingQuote = value[value.length - 1] === '"'; const hasTrailingSlash = value[value.length - 1] === '\\'; diff --git a/src/language/printer.js b/src/language/printer.js index 334742d967..4877072969 100644 --- a/src/language/printer.js +++ b/src/language/printer.js @@ -332,10 +332,7 @@ function indent(str: string): string { return wrap(' ', str.replace(/\n/g, '\n ')); } -function isMultiline(str: string): boolean { - return str.indexOf('\n') !== -1; -} - function hasMultilineItems(maybeArray: ?Array): boolean { - return maybeArray != null && maybeArray.some(isMultiline); + // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') + return maybeArray?.some((str) => str.includes('\n')) ?? false; } diff --git a/src/type/validate.js b/src/type/validate.js index fdaa5f8e45..4d39256ac4 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -441,7 +441,7 @@ function validateTypeImplementsAncestors( ): void { const ifaceInterfaces = type.getInterfaces(); for (const transitive of iface.getInterfaces()) { - if (ifaceInterfaces.indexOf(transitive) === -1) { + if (!ifaceInterfaces.includes(transitive)) { context.reportError( transitive === type ? `Type ${type.name} cannot implement ${iface.name} because it would create a circular reference.` diff --git a/src/utilities/__tests__/stripIgnoredCharacters-test.js b/src/utilities/__tests__/stripIgnoredCharacters-test.js index e73fa56362..293258707c 100644 --- a/src/utilities/__tests__/stripIgnoredCharacters-test.js +++ b/src/utilities/__tests__/stripIgnoredCharacters-test.js @@ -370,7 +370,7 @@ describe('stripIgnoredCharacters', () => { expectStripped('""",|"""').toStayTheSame(); const ignoredTokensWithoutFormatting = ignoredTokens.filter( - (token) => ['\n', '\r', '\r\n', '\t', ' '].indexOf(token) === -1, + (token) => !['\n', '\r', '\r\n', '\t', ' '].includes(token), ); for (const ignored of ignoredTokensWithoutFormatting) { expectStripped('"""|' + ignored + '|"""').toStayTheSame(); diff --git a/src/utilities/findBreakingChanges.js b/src/utilities/findBreakingChanges.js index 8fb29c87c1..2a13d4655b 100644 --- a/src/utilities/findBreakingChanges.js +++ b/src/utilities/findBreakingChanges.js @@ -156,7 +156,7 @@ function findDirectiveChanges( } for (const location of oldDirective.locations) { - if (newDirective.locations.indexOf(location) === -1) { + if (!newDirective.locations.includes(location)) { schemaChanges.push({ type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED, description: `${location} was removed from ${oldDirective.name}.`, diff --git a/src/validation/rules/KnownArgumentNamesRule.js b/src/validation/rules/KnownArgumentNamesRule.js index dbd8fb82fe..d769fe4966 100644 --- a/src/validation/rules/KnownArgumentNamesRule.js +++ b/src/validation/rules/KnownArgumentNamesRule.js @@ -78,7 +78,7 @@ export function KnownArgumentNamesOnDirectivesRule( if (directiveNode.arguments && knownArgs) { for (const argNode of directiveNode.arguments) { const argName = argNode.name.value; - if (knownArgs.indexOf(argName) === -1) { + if (!knownArgs.includes(argName)) { const suggestions = suggestionList(argName, knownArgs); context.reportError( new GraphQLError( diff --git a/src/validation/rules/KnownDirectivesRule.js b/src/validation/rules/KnownDirectivesRule.js index 05a0d3b261..8c1e9191d1 100644 --- a/src/validation/rules/KnownDirectivesRule.js +++ b/src/validation/rules/KnownDirectivesRule.js @@ -55,7 +55,7 @@ export function KnownDirectivesRule( } const candidateLocation = getDirectiveLocationForASTPath(ancestors); - if (candidateLocation && locations.indexOf(candidateLocation) === -1) { + if (candidateLocation && !locations.includes(candidateLocation)) { context.reportError( new GraphQLError( `Directive "@${name}" may not be used on ${candidateLocation}.`, diff --git a/src/validation/rules/KnownTypeNamesRule.js b/src/validation/rules/KnownTypeNamesRule.js index 3c49b3840a..bf443861a2 100644 --- a/src/validation/rules/KnownTypeNamesRule.js +++ b/src/validation/rules/KnownTypeNamesRule.js @@ -48,7 +48,7 @@ export function KnownTypeNamesRule( if (!existingTypesMap[typeName] && !definedTypes[typeName]) { const definitionNode = ancestors[2] ?? parent; const isSDL = definitionNode != null && isSDLNode(definitionNode); - if (isSDL && isStandardTypeName(typeName)) { + if (isSDL && standardTypeNames.includes(typeName)) { return; } @@ -71,10 +71,6 @@ const standardTypeNames = [...specifiedScalarTypes, ...introspectionTypes].map( (type) => type.name, ); -function isStandardTypeName(typeName: string): boolean { - return standardTypeNames.indexOf(typeName) !== -1; -} - function isSDLNode(value: ASTNode | $ReadOnlyArray): boolean { return ( !Array.isArray(value) &&