Skip to content

Commit

Permalink
enable unicorn/prefer-switch rule (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina authored Mar 4, 2023
1 parent b9c1332 commit 392e193
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ module.exports = {
'import/no-unresolved': ['error', { ignore: ['^node:'] }],
'unicorn/prefer-string-replace-all': 'error',

'unicorn/prefer-switch': 'error',
// TODO: Fix all errors for the following rules included in recommended config
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
Expand Down
43 changes: 27 additions & 16 deletions packages/codemirror-graphql/src/variables/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,12 @@ function getVariablesHint(
}
}
}

interface VariableTypeInfo {
type?: Maybe<GraphQLInputType>;
fields?: Maybe<GraphQLInputFieldMap>;
}

// Utility for collecting rich type information given any token's state
// from the graphql-variables-mode parser.
function getTypeInfo(
Expand All @@ -187,22 +189,31 @@ function getTypeInfo(
};

forEachState(tokenState, state => {
if (state.kind === 'Variable') {
info.type = variableToType[state.name!];
} else if (state.kind === 'ListValue') {
const nullableType = info.type ? getNullableType(info.type) : undefined;
info.type =
nullableType instanceof GraphQLList ? nullableType.ofType : null;
} else if (state.kind === 'ObjectValue') {
const objectType = info.type ? getNamedType(info.type) : undefined;
info.fields =
objectType instanceof GraphQLInputObjectType
? objectType.getFields()
: null;
} else if (state.kind === 'ObjectField') {
const objectField =
state.name && info.fields ? info.fields[state.name] : null;
info.type = objectField?.type;
switch (state.kind) {
case 'Variable': {
info.type = variableToType[state.name!];
break;
}
case 'ListValue': {
const nullableType = info.type ? getNullableType(info.type) : undefined;
info.type =
nullableType instanceof GraphQLList ? nullableType.ofType : null;
break;
}
case 'ObjectValue': {
const objectType = info.type ? getNamedType(info.type) : undefined;
info.fields =
objectType instanceof GraphQLInputObjectType
? objectType.getFields()
: null;
break;
}
case 'ObjectField': {
const objectField =
state.name && info.fields ? info.fields[state.name] : null;
info.type = objectField?.type;
break;
}
}
});

Expand Down

0 comments on commit 392e193

Please sign in to comment.