Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable unicorn/prefer-includes #2937

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/modern-vans-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'codemirror-graphql': patch
'@graphiql/react': patch
'@graphiql/toolkit': patch
'graphql-language-service': patch
'graphql-language-service-server': patch
'vscode-graphql': patch
'vscode-graphql-execution': patch
---

enable `unicorn/prefer-includes`
2 changes: 1 addition & 1 deletion packages/codemirror-graphql/src/utils/jump-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function onKeyDown(cm: CodeMirror.Editor, event: KeyboardEvent) {
const isMac =
typeof navigator !== 'undefined' &&
navigator &&
navigator.appVersion.indexOf('Mac') !== -1;
navigator.appVersion.includes('Mac');

function isJumpModifier(key: string) {
return key === (isMac ? 'Meta' : 'Control');
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/explorer/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function isMatch(sourceText: string, searchValue: string) {
const escaped = searchValue.replace(/[^_0-9A-Za-z]/g, ch => '\\' + ch);
return sourceText.search(new RegExp(escaped, 'i')) !== -1;
} catch (e) {
return sourceText.toLowerCase().indexOf(searchValue.toLowerCase()) !== -1;
return sourceText.toLowerCase().includes(searchValue.toLowerCase());
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-toolkit/src/graphql-helpers/merge-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ function inlineRelevantFragmentSpreads(
? getNamedType(selectionSetType).name
: null;
const outputSelections = [];
const seenSpreads = [];
const seenSpreads: string[] = [];
for (let selection of selections) {
if (selection.kind === 'FragmentSpread') {
const fragmentName = selection.name.value;
if (!selection.directives || selection.directives.length === 0) {
if (seenSpreads.indexOf(fragmentName) >= 0) {
if (seenSpreads.includes(fragmentName)) {
/* It's a duplicate - skip it! */
continue;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export function getSelectedOperationName(

// If a previous selection still exists, continue to use it.
const names = operations.map(op => op.name?.value);
if (
prevSelectedOperationName &&
names.indexOf(prevSelectedOperationName) !== -1
) {
if (prevSelectedOperationName && names.includes(prevSelectedOperationName)) {
return prevSelectedOperationName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,7 @@ export class MessageProcessor {
}
_isRelayCompatMode(query: string): boolean {
return (
query.indexOf('RelayCompat') !== -1 ||
query.indexOf('react-relay/compat') !== -1
query.includes('RelayCompat') || query.includes('react-relay/compat')
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ const IGNORED_KEYS: { [key: string]: boolean } = {
};

function getGraphQLTagName(tag: Expression): string | null {
if (
tag.type === 'Identifier' &&
DEFAULT_STABLE_TAGS.some(t => t === tag.name)
) {
if (tag.type === 'Identifier' && DEFAULT_STABLE_TAGS.includes(tag.name)) {
return tag.name;
}
if (
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql-language-service-server/src/parseDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export function parseDocument(
// Check if the text content includes a GraphQLV query.
// If the text doesn't include GraphQL queries, do not proceed.
const ext = extname(uri);
if (fileExtensions.some(e => e === ext)) {
if (DEFAULT_TAGS.some(t => t === text)) {
if (fileExtensions.includes(ext)) {
if (DEFAULT_TAGS.includes(text)) {
return [];
}
const templates = findGraphQLTags(text, ext, uri, logger);
return templates.map(({ template, range }) => ({ query: template, range }));
}
if (graphQLFileExtensions.some(e => e === ext)) {
if (graphQLFileExtensions.includes(ext)) {
const query = text;
if (!query && query !== '') {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ describe('getAutocompleteSuggestions', () => {
externalFragments,
options,
)
.filter(
field => !['__schema', '__type'].some(name => name === field.label),
)
.filter(field => !['__schema', '__type'].includes(field.label))
.sort((a, b) => a.label.localeCompare(b.label))
.map(suggestion => {
// TODO: A PR where we do `const { type, ..rest} = suggestion; return rest;`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,51 +1061,47 @@ export function canUseDirective(
const locations = directive.locations;
switch (kind) {
case RuleKinds.QUERY:
return locations.indexOf(DirectiveLocation.QUERY) !== -1;
return locations.includes(DirectiveLocation.QUERY);
case RuleKinds.MUTATION:
return locations.indexOf(DirectiveLocation.MUTATION) !== -1;
return locations.includes(DirectiveLocation.MUTATION);
case RuleKinds.SUBSCRIPTION:
return locations.indexOf(DirectiveLocation.SUBSCRIPTION) !== -1;
return locations.includes(DirectiveLocation.SUBSCRIPTION);
case RuleKinds.FIELD:
case RuleKinds.ALIASED_FIELD:
return locations.indexOf(DirectiveLocation.FIELD) !== -1;
return locations.includes(DirectiveLocation.FIELD);
case RuleKinds.FRAGMENT_DEFINITION:
return locations.indexOf(DirectiveLocation.FRAGMENT_DEFINITION) !== -1;
return locations.includes(DirectiveLocation.FRAGMENT_DEFINITION);
case RuleKinds.FRAGMENT_SPREAD:
return locations.indexOf(DirectiveLocation.FRAGMENT_SPREAD) !== -1;
return locations.includes(DirectiveLocation.FRAGMENT_SPREAD);
case RuleKinds.INLINE_FRAGMENT:
return locations.indexOf(DirectiveLocation.INLINE_FRAGMENT) !== -1;
return locations.includes(DirectiveLocation.INLINE_FRAGMENT);

// Schema Definitions
case RuleKinds.SCHEMA_DEF:
return locations.indexOf(DirectiveLocation.SCHEMA) !== -1;
return locations.includes(DirectiveLocation.SCHEMA);
case RuleKinds.SCALAR_DEF:
return locations.indexOf(DirectiveLocation.SCALAR) !== -1;
return locations.includes(DirectiveLocation.SCALAR);
case RuleKinds.OBJECT_TYPE_DEF:
return locations.indexOf(DirectiveLocation.OBJECT) !== -1;
return locations.includes(DirectiveLocation.OBJECT);
case RuleKinds.FIELD_DEF:
return locations.indexOf(DirectiveLocation.FIELD_DEFINITION) !== -1;
return locations.includes(DirectiveLocation.FIELD_DEFINITION);
case RuleKinds.INTERFACE_DEF:
return locations.indexOf(DirectiveLocation.INTERFACE) !== -1;
return locations.includes(DirectiveLocation.INTERFACE);
case RuleKinds.UNION_DEF:
return locations.indexOf(DirectiveLocation.UNION) !== -1;
return locations.includes(DirectiveLocation.UNION);
case RuleKinds.ENUM_DEF:
return locations.indexOf(DirectiveLocation.ENUM) !== -1;
return locations.includes(DirectiveLocation.ENUM);
case RuleKinds.ENUM_VALUE:
return locations.indexOf(DirectiveLocation.ENUM_VALUE) !== -1;
return locations.includes(DirectiveLocation.ENUM_VALUE);
case RuleKinds.INPUT_DEF:
return locations.indexOf(DirectiveLocation.INPUT_OBJECT) !== -1;
return locations.includes(DirectiveLocation.INPUT_OBJECT);
case RuleKinds.INPUT_VALUE_DEF:
const prevStateKind = state.prevState?.kind;
switch (prevStateKind) {
case RuleKinds.ARGUMENTS_DEF:
return (
locations.indexOf(DirectiveLocation.ARGUMENT_DEFINITION) !== -1
);
return locations.includes(DirectiveLocation.ARGUMENT_DEFINITION);
case RuleKinds.INPUT_DEF:
return (
locations.indexOf(DirectiveLocation.INPUT_FIELD_DEFINITION) !== -1
);
return locations.includes(DirectiveLocation.INPUT_FIELD_DEFINITION);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function validateWithCustomRules(
}
const errors = validate(schema, ast, rules);
return errors.filter(error => {
if (error.message.indexOf('Unknown directive') !== -1 && error.nodes) {
if (error.message.includes('Unknown directive') && error.nodes) {
const node = error.nodes[0];
if (node && node.kind === Kind.DIRECTIVE) {
const name = node.name.value;
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-graphql/src/apis/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function updateStatusBar(

if (
editor &&
statusBarActivationLanguageIds.indexOf(editor.document.languageId) > -1
statusBarActivationLanguageIds.includes(editor.document.languageId)
) {
statusBarItem.show();
} else {
Expand Down
2 changes: 1 addition & 1 deletion scripts/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const executable = join(
os.platform() === 'win32' ? 'prettier.cmd' : 'prettier',
);
const ignorePath = ['--ignore-path', '.eslintignore'];
const check = process.argv.indexOf('--check') !== -1;
const check = process.argv.includes('--check');
const mode = check ? '--list-different' : '--write';
process.chdir(root);

Expand Down