Skip to content

Commit f263f77

Browse files
authored
enable prefer-destructuring rule (#2963)
* enable `prefer-destructuring` rule * fixes
1 parent 0434d94 commit f263f77

29 files changed

Lines changed: 71 additions & 73 deletions

File tree

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

.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ module.exports = {
187187
'no-continue': 0,
188188
'no-inline-comments': 0,
189189
'no-mixed-operators': 0,
190-
'no-negated-condition': 'error',
190+
'no-negated-condition': 'off',
191+
'unicorn/no-negated-condition': 'error',
191192
'no-nested-ternary': 0,
192193
'no-new-object': 1,
193194
'no-plusplus': 0,
@@ -260,6 +261,7 @@ module.exports = {
260261
// Jest rules
261262
'jest/no-conditional-expect': 0,
262263

264+
'prefer-destructuring': ['error', { VariableDeclarator: { object: true } }],
263265
'promise/no-multiple-resolved': 'error',
264266
'sonarjs/no-redundant-jump': 'error',
265267
'unicorn/prefer-logical-operator-over-ternary': 'error',

packages/codemirror-graphql/src/hint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ CodeMirror.registerHelper(
7070
editor: CodeMirror.Editor,
7171
options: GraphQLHintOptions,
7272
): IHints | undefined => {
73-
const schema = options.schema;
73+
const { schema } = options;
7474
if (!schema) {
7575
return;
7676
}

packages/codemirror-graphql/src/info.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ CodeMirror.registerHelper(
6161
if (!options.schema || !token.state) {
6262
return;
6363
}
64-
65-
const state = token.state;
66-
const kind = state.kind;
67-
const step = state.step;
64+
const { kind, step } = token.state;
6865
const typeInfo = getTypeInfo(options.schema, token.state);
6966

7067
// Given a Schema and a Token, produce the contents of an info tooltip.
@@ -238,7 +235,7 @@ function renderDescription(
238235
| GraphQLEnumValue
239236
| GraphQLType,
240237
) {
241-
const description = (def as GraphQLInputField).description;
238+
const { description } = def as GraphQLInputField;
242239
if (description) {
243240
const descriptionDiv = document.createElement('div');
244241
descriptionDiv.className = 'info-description';
@@ -293,7 +290,7 @@ function text(
293290
ref: Maybe<SchemaReference> = null,
294291
) {
295292
if (className) {
296-
const onClick = options.onClick;
293+
const { onClick } = options;
297294
let node;
298295
if (onClick) {
299296
node = document.createElement('a');

packages/codemirror-graphql/src/jump.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ CodeMirror.registerHelper(
5353
// Given a Schema and a Token, produce a "SchemaReference" which refers to
5454
// the particular artifact from the schema (such as a type, field, argument,
5555
// or directive) that token references.
56-
const state = token.state;
57-
const kind = state.kind;
58-
const step = state.step;
56+
const { state } = token;
57+
const { kind, step } = state;
5958
const typeInfo = getTypeInfo(options.schema, state);
6059

6160
if (

packages/codemirror-graphql/src/lint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CodeMirror.registerHelper(
4242
'lint',
4343
'graphql',
4444
(text: string, options: GraphQLLintOptions): CodeMirror.Annotation[] => {
45-
const schema = options.schema;
45+
const { schema } = options;
4646
const rawResults = getDiagnostics(
4747
text,
4848
schema,

packages/codemirror-graphql/src/results/mode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function indent(
5252
state: State,
5353
textAfter: string,
5454
) {
55-
const levels = state.levels;
55+
const { levels } = state;
5656
// If there is no stack of levels, use the current level.
5757
// Otherwise, use the top level, preemptively dedenting for close braces.
5858
const level =

packages/codemirror-graphql/src/utils/collectVariables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function collectVariables(
2424
const variableToType = Object.create(null);
2525
documentAST.definitions.forEach(definition => {
2626
if (definition.kind === 'OperationDefinition') {
27-
const variableDefinitions = definition.variableDefinitions;
27+
const { variableDefinitions } = definition;
2828
if (variableDefinitions) {
2929
variableDefinitions.forEach(({ variable, type }) => {
3030
const inputType = typeFromAST(schema, type as NamedTypeNode);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function createState(options: GraphQLInfoOptions) {
4545
}
4646

4747
function getHoverTime(cm: CodeMirror.Editor) {
48-
const options = cm.state.info.options;
48+
const { options } = cm.state.info;
4949
return options?.hoverTime || 500;
5050
}
5151

@@ -96,7 +96,7 @@ function onMouseHover(cm: CodeMirror.Editor, box: DOMRect) {
9696
});
9797

9898
const state = cm.state.info;
99-
const options = state.options;
99+
const { options } = state;
100100
const render = options.render || cm.getHelper(pos, 'info');
101101
if (render) {
102102
const token = cm.getTokenAt(pos, true);

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function onKeyDown(cm: CodeMirror.Editor, event: KeyboardEvent) {
103103
};
104104

105105
const onClick = (clickEvent: MouseEvent) => {
106-
const destination = cm.state.jump.destination;
106+
const { destination } = cm.state.jump;
107107
if (destination) {
108108
cm.state.jump.options.onClick(destination, clickEvent);
109109
}
@@ -134,11 +134,9 @@ function enableJumpMode(cm: CodeMirror.Editor) {
134134
return;
135135
}
136136

137-
const cursor = cm.state.jump.cursor;
137+
const { cursor, options } = cm.state.jump;
138138
const pos = cm.coordsChar(cursor);
139139
const token = cm.getTokenAt(pos, true);
140-
141-
const options = cm.state.jump.options;
142140
const getDestination = options.getDestination || cm.getHelper(pos, 'jump');
143141
if (getDestination) {
144142
const destination = getDestination(token, options, cm);
@@ -156,7 +154,7 @@ function enableJumpMode(cm: CodeMirror.Editor) {
156154
}
157155

158156
function disableJumpMode(cm: CodeMirror.Editor) {
159-
const marker = cm.state.jump.marker;
157+
const { marker } = cm.state.jump;
160158
cm.state.jump.marker = null;
161159
cm.state.jump.destination = null;
162160

0 commit comments

Comments
 (0)