Skip to content

Commit c70d916

Browse files
authored
enable unicorn/prefer-includes (#2937)
* enable `unicorn/prefer-includes` * fix build
1 parent 33311ef commit c70d916

13 files changed

Lines changed: 43 additions & 45 deletions

File tree

.changeset/modern-vans-warn.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'codemirror-graphql': patch
3+
'@graphiql/react': patch
4+
'@graphiql/toolkit': patch
5+
'graphql-language-service': patch
6+
'graphql-language-service-server': patch
7+
'vscode-graphql': patch
8+
'vscode-graphql-execution': patch
9+
---
10+
11+
enable `unicorn/prefer-includes`

packages/codemirror-graphql/src/utils/jump-addon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function onKeyDown(cm: CodeMirror.Editor, event: KeyboardEvent) {
123123
const isMac =
124124
typeof navigator !== 'undefined' &&
125125
navigator &&
126-
navigator.appVersion.indexOf('Mac') !== -1;
126+
navigator.appVersion.includes('Mac');
127127

128128
function isJumpModifier(key: string) {
129129
return key === (isMac ? 'Meta' : 'Control');

packages/graphiql-react/src/explorer/components/search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function isMatch(sourceText: string, searchValue: string) {
287287
const escaped = searchValue.replace(/[^_0-9A-Za-z]/g, ch => '\\' + ch);
288288
return sourceText.search(new RegExp(escaped, 'i')) !== -1;
289289
} catch (e) {
290-
return sourceText.toLowerCase().indexOf(searchValue.toLowerCase()) !== -1;
290+
return sourceText.toLowerCase().includes(searchValue.toLowerCase());
291291
}
292292
}
293293

packages/graphiql-toolkit/src/graphql-helpers/merge-ast.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ function inlineRelevantFragmentSpreads(
5656
? getNamedType(selectionSetType).name
5757
: null;
5858
const outputSelections = [];
59-
const seenSpreads = [];
59+
const seenSpreads: string[] = [];
6060
for (let selection of selections) {
6161
if (selection.kind === 'FragmentSpread') {
6262
const fragmentName = selection.name.value;
6363
if (!selection.directives || selection.directives.length === 0) {
64-
if (seenSpreads.indexOf(fragmentName) >= 0) {
64+
if (seenSpreads.includes(fragmentName)) {
6565
/* It's a duplicate - skip it! */
6666
continue;
6767
} else {

packages/graphiql-toolkit/src/graphql-helpers/operation-name.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ export function getSelectedOperationName(
1616

1717
// If a previous selection still exists, continue to use it.
1818
const names = operations.map(op => op.name?.value);
19-
if (
20-
prevSelectedOperationName &&
21-
names.indexOf(prevSelectedOperationName) !== -1
22-
) {
19+
if (prevSelectedOperationName && names.includes(prevSelectedOperationName)) {
2320
return prevSelectedOperationName;
2421
}
2522

packages/graphql-language-service-server/src/MessageProcessor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,7 @@ export class MessageProcessor {
11601160
}
11611161
_isRelayCompatMode(query: string): boolean {
11621162
return (
1163-
query.indexOf('RelayCompat') !== -1 ||
1164-
query.indexOf('react-relay/compat') !== -1
1163+
query.includes('RelayCompat') || query.includes('react-relay/compat')
11651164
);
11661165
}
11671166

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,7 @@ const IGNORED_KEYS: { [key: string]: boolean } = {
260260
};
261261

262262
function getGraphQLTagName(tag: Expression): string | null {
263-
if (
264-
tag.type === 'Identifier' &&
265-
DEFAULT_STABLE_TAGS.some(t => t === tag.name)
266-
) {
263+
if (tag.type === 'Identifier' && DEFAULT_STABLE_TAGS.includes(tag.name)) {
267264
return tag.name;
268265
}
269266
if (

packages/graphql-language-service-server/src/parseDocument.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ export function parseDocument(
5353
// Check if the text content includes a GraphQLV query.
5454
// If the text doesn't include GraphQL queries, do not proceed.
5555
const ext = extname(uri);
56-
if (fileExtensions.some(e => e === ext)) {
57-
if (DEFAULT_TAGS.some(t => t === text)) {
56+
if (fileExtensions.includes(ext)) {
57+
if (DEFAULT_TAGS.includes(text)) {
5858
return [];
5959
}
6060
const templates = findGraphQLTags(text, ext, uri, logger);
6161
return templates.map(({ template, range }) => ({ query: template, range }));
6262
}
63-
if (graphQLFileExtensions.some(e => e === ext)) {
63+
if (graphQLFileExtensions.includes(ext)) {
6464
const query = text;
6565
if (!query && query !== '') {
6666
return [];

packages/graphql-language-service/src/interface/__tests__/getAutocompleteSuggestions-test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ describe('getAutocompleteSuggestions', () => {
8484
externalFragments,
8585
options,
8686
)
87-
.filter(
88-
field => !['__schema', '__type'].some(name => name === field.label),
89-
)
87+
.filter(field => !['__schema', '__type'].includes(field.label))
9088
.sort((a, b) => a.label.localeCompare(b.label))
9189
.map(suggestion => {
9290
// TODO: A PR where we do `const { type, ..rest} = suggestion; return rest;`

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,51 +1061,47 @@ export function canUseDirective(
10611061
const locations = directive.locations;
10621062
switch (kind) {
10631063
case RuleKinds.QUERY:
1064-
return locations.indexOf(DirectiveLocation.QUERY) !== -1;
1064+
return locations.includes(DirectiveLocation.QUERY);
10651065
case RuleKinds.MUTATION:
1066-
return locations.indexOf(DirectiveLocation.MUTATION) !== -1;
1066+
return locations.includes(DirectiveLocation.MUTATION);
10671067
case RuleKinds.SUBSCRIPTION:
1068-
return locations.indexOf(DirectiveLocation.SUBSCRIPTION) !== -1;
1068+
return locations.includes(DirectiveLocation.SUBSCRIPTION);
10691069
case RuleKinds.FIELD:
10701070
case RuleKinds.ALIASED_FIELD:
1071-
return locations.indexOf(DirectiveLocation.FIELD) !== -1;
1071+
return locations.includes(DirectiveLocation.FIELD);
10721072
case RuleKinds.FRAGMENT_DEFINITION:
1073-
return locations.indexOf(DirectiveLocation.FRAGMENT_DEFINITION) !== -1;
1073+
return locations.includes(DirectiveLocation.FRAGMENT_DEFINITION);
10741074
case RuleKinds.FRAGMENT_SPREAD:
1075-
return locations.indexOf(DirectiveLocation.FRAGMENT_SPREAD) !== -1;
1075+
return locations.includes(DirectiveLocation.FRAGMENT_SPREAD);
10761076
case RuleKinds.INLINE_FRAGMENT:
1077-
return locations.indexOf(DirectiveLocation.INLINE_FRAGMENT) !== -1;
1077+
return locations.includes(DirectiveLocation.INLINE_FRAGMENT);
10781078

10791079
// Schema Definitions
10801080
case RuleKinds.SCHEMA_DEF:
1081-
return locations.indexOf(DirectiveLocation.SCHEMA) !== -1;
1081+
return locations.includes(DirectiveLocation.SCHEMA);
10821082
case RuleKinds.SCALAR_DEF:
1083-
return locations.indexOf(DirectiveLocation.SCALAR) !== -1;
1083+
return locations.includes(DirectiveLocation.SCALAR);
10841084
case RuleKinds.OBJECT_TYPE_DEF:
1085-
return locations.indexOf(DirectiveLocation.OBJECT) !== -1;
1085+
return locations.includes(DirectiveLocation.OBJECT);
10861086
case RuleKinds.FIELD_DEF:
1087-
return locations.indexOf(DirectiveLocation.FIELD_DEFINITION) !== -1;
1087+
return locations.includes(DirectiveLocation.FIELD_DEFINITION);
10881088
case RuleKinds.INTERFACE_DEF:
1089-
return locations.indexOf(DirectiveLocation.INTERFACE) !== -1;
1089+
return locations.includes(DirectiveLocation.INTERFACE);
10901090
case RuleKinds.UNION_DEF:
1091-
return locations.indexOf(DirectiveLocation.UNION) !== -1;
1091+
return locations.includes(DirectiveLocation.UNION);
10921092
case RuleKinds.ENUM_DEF:
1093-
return locations.indexOf(DirectiveLocation.ENUM) !== -1;
1093+
return locations.includes(DirectiveLocation.ENUM);
10941094
case RuleKinds.ENUM_VALUE:
1095-
return locations.indexOf(DirectiveLocation.ENUM_VALUE) !== -1;
1095+
return locations.includes(DirectiveLocation.ENUM_VALUE);
10961096
case RuleKinds.INPUT_DEF:
1097-
return locations.indexOf(DirectiveLocation.INPUT_OBJECT) !== -1;
1097+
return locations.includes(DirectiveLocation.INPUT_OBJECT);
10981098
case RuleKinds.INPUT_VALUE_DEF:
10991099
const prevStateKind = state.prevState?.kind;
11001100
switch (prevStateKind) {
11011101
case RuleKinds.ARGUMENTS_DEF:
1102-
return (
1103-
locations.indexOf(DirectiveLocation.ARGUMENT_DEFINITION) !== -1
1104-
);
1102+
return locations.includes(DirectiveLocation.ARGUMENT_DEFINITION);
11051103
case RuleKinds.INPUT_DEF:
1106-
return (
1107-
locations.indexOf(DirectiveLocation.INPUT_FIELD_DEFINITION) !== -1
1108-
);
1104+
return locations.includes(DirectiveLocation.INPUT_FIELD_DEFINITION);
11091105
}
11101106
}
11111107

0 commit comments

Comments
 (0)