@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810155929-e89edf7
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -0
- package/cjs/cache.js +10 -19
- package/cjs/configs/index.d.ts +42 -16
- package/cjs/configs/index.js +10 -19
- package/cjs/configs/operations-all.d.ts +4 -3
- package/cjs/configs/operations-all.js +5 -4
- package/cjs/configs/operations-recommended.d.ts +3 -1
- package/cjs/configs/operations-recommended.js +3 -1
- package/cjs/configs/schema-all.d.ts +6 -1
- package/cjs/configs/schema-all.js +5 -2
- package/cjs/configs/schema-recommended.d.ts +19 -1
- package/cjs/configs/schema-recommended.js +22 -2
- package/cjs/documents.js +17 -32
- package/cjs/estree-converter/converter.js +14 -27
- package/cjs/estree-converter/index.js +4 -7
- package/cjs/estree-converter/types.js +3 -5
- package/cjs/estree-converter/utils.d.ts +2 -3
- package/cjs/estree-converter/utils.js +15 -45
- package/cjs/flat-configs.d.ts +59 -12
- package/cjs/flat-configs.js +9 -14
- package/cjs/graphql-config.d.ts +4 -3
- package/cjs/graphql-config.js +23 -44
- package/cjs/index.d.ts +10 -4
- package/cjs/index.js +8 -16
- package/cjs/parser.d.ts +4 -3
- package/cjs/parser.js +38 -45
- package/cjs/processor.d.ts +5 -1
- package/cjs/processor.js +25 -57
- package/cjs/rules/alphabetize.d.ts +6 -16
- package/cjs/rules/alphabetize.js +60 -132
- package/cjs/rules/description-style.d.ts +4 -3
- package/cjs/rules/description-style.js +11 -18
- package/cjs/rules/graphql-js-validation.d.ts +4 -3
- package/cjs/rules/graphql-js-validation.js +151 -225
- package/cjs/rules/index.d.ts +15 -13
- package/cjs/rules/index.js +8 -45
- package/cjs/rules/input-name.d.ts +4 -3
- package/cjs/rules/input-name.js +43 -59
- package/cjs/rules/lone-executable-definition.d.ts +6 -5
- package/cjs/rules/lone-executable-definition.js +14 -28
- package/cjs/rules/match-document-filename.d.ts +4 -3
- package/cjs/rules/match-document-filename.js +39 -70
- package/cjs/rules/naming-convention.d.ts +4 -3
- package/cjs/rules/naming-convention.js +56 -74
- package/cjs/rules/no-anonymous-operations.d.ts +4 -3
- package/cjs/rules/no-anonymous-operations.js +11 -18
- package/cjs/rules/no-deprecated.d.ts +4 -3
- package/cjs/rules/no-deprecated.js +15 -29
- package/cjs/rules/no-duplicate-fields.d.ts +4 -3
- package/cjs/rules/no-duplicate-fields.js +13 -23
- package/cjs/rules/no-hashtag-description.d.ts +4 -3
- package/cjs/rules/no-hashtag-description.js +16 -29
- package/cjs/rules/no-one-place-fragments.d.ts +4 -3
- package/cjs/rules/no-one-place-fragments.js +17 -29
- package/cjs/rules/no-root-type.d.ts +4 -3
- package/cjs/rules/no-root-type.js +15 -25
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
- package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
- package/cjs/rules/no-typename-prefix.d.ts +4 -3
- package/cjs/rules/no-typename-prefix.js +26 -33
- package/cjs/rules/no-unreachable-types.d.ts +4 -3
- package/cjs/rules/no-unreachable-types.js +25 -47
- package/cjs/rules/no-unused-fields.d.ts +4 -3
- package/cjs/rules/no-unused-fields.js +24 -49
- package/cjs/rules/relay-arguments.d.ts +4 -3
- package/cjs/rules/relay-arguments.js +20 -43
- package/cjs/rules/relay-connection-types.d.ts +4 -3
- package/cjs/rules/relay-connection-types.js +14 -45
- package/cjs/rules/relay-edge-types.d.ts +4 -3
- package/cjs/rules/relay-edge-types.js +48 -99
- package/cjs/rules/relay-page-info.d.ts +4 -3
- package/cjs/rules/relay-page-info.js +21 -44
- package/cjs/rules/require-deprecation-date.d.ts +4 -3
- package/cjs/rules/require-deprecation-date.js +15 -31
- package/cjs/rules/require-deprecation-reason.d.ts +4 -3
- package/cjs/rules/require-deprecation-reason.js +12 -20
- package/cjs/rules/require-description.d.ts +4 -3
- package/cjs/rules/require-description.js +39 -65
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
- package/cjs/rules/require-import-fragment.d.ts +4 -3
- package/cjs/rules/require-import-fragment.js +22 -40
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
- package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
- package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
- package/cjs/rules/require-nullable-result-in-root.js +34 -44
- package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
- package/cjs/rules/require-selections.js +198 -0
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
- package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
- package/cjs/rules/selection-set-depth.d.ts +4 -3
- package/cjs/rules/selection-set-depth.js +18 -34
- package/cjs/rules/strict-id-in-types.d.ts +4 -3
- package/cjs/rules/strict-id-in-types.js +25 -43
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
- package/cjs/rules/unique-fragment-name.d.ts +3 -2
- package/cjs/rules/unique-fragment-name.js +24 -36
- package/cjs/rules/unique-operation-name.d.ts +4 -3
- package/cjs/rules/unique-operation-name.js +10 -12
- package/cjs/schema.d.ts +4 -3
- package/cjs/schema.js +14 -27
- package/cjs/siblings.d.ts +24 -8
- package/cjs/siblings.js +42 -82
- package/cjs/types.d.ts +74 -7
- package/cjs/types.js +3 -5
- package/cjs/utils.d.ts +3 -2
- package/cjs/utils.js +27 -44
- package/esm/cache.js +4 -8
- package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
- package/esm/configs/index.d.mts +42 -16
- package/esm/configs/index.js +4 -4
- package/esm/configs/operations-all.d.mts +4 -3
- package/esm/configs/operations-all.js +6 -5
- package/esm/configs/operations-recommended.d.mts +3 -1
- package/esm/configs/operations-recommended.js +4 -2
- package/esm/configs/schema-all.d.mts +6 -1
- package/esm/configs/schema-all.js +6 -3
- package/esm/configs/schema-recommended.d.mts +19 -1
- package/esm/configs/schema-recommended.js +23 -3
- package/esm/configs/{relay.js → schema-relay.js} +4 -4
- package/esm/documents.js +10 -17
- package/esm/estree-converter/converter.js +9 -18
- package/esm/estree-converter/utils.d.mts +2 -3
- package/esm/estree-converter/utils.js +11 -38
- package/esm/flat-configs.d.mts +59 -12
- package/esm/flat-configs.js +4 -5
- package/esm/graphql-config.d.mts +4 -3
- package/esm/graphql-config.js +18 -34
- package/esm/index.d.mts +10 -4
- package/esm/index.js +1 -1
- package/esm/parser.d.mts +4 -3
- package/esm/parser.js +33 -27
- package/esm/processor.d.mts +5 -1
- package/esm/processor.js +21 -46
- package/esm/rules/alphabetize.d.mts +6 -16
- package/esm/rules/alphabetize.js +53 -118
- package/esm/rules/description-style.d.mts +4 -3
- package/esm/rules/description-style.js +7 -11
- package/esm/rules/graphql-js-validation.d.mts +4 -3
- package/esm/rules/graphql-js-validation.js +178 -218
- package/esm/rules/index.d.mts +15 -13
- package/esm/rules/index.js +5 -5
- package/esm/rules/input-name.d.mts +4 -3
- package/esm/rules/input-name.js +39 -52
- package/esm/rules/lone-executable-definition.d.mts +6 -5
- package/esm/rules/lone-executable-definition.js +10 -20
- package/esm/rules/match-document-filename.d.mts +4 -3
- package/esm/rules/match-document-filename.js +35 -61
- package/esm/rules/naming-convention.d.mts +4 -3
- package/esm/rules/naming-convention.js +51 -65
- package/esm/rules/no-anonymous-operations.d.mts +4 -3
- package/esm/rules/no-anonymous-operations.js +6 -9
- package/esm/rules/no-deprecated.d.mts +4 -3
- package/esm/rules/no-deprecated.js +10 -20
- package/esm/rules/no-duplicate-fields.d.mts +4 -3
- package/esm/rules/no-duplicate-fields.js +9 -16
- package/esm/rules/no-hashtag-description.d.mts +4 -3
- package/esm/rules/no-hashtag-description.js +11 -20
- package/esm/rules/no-one-place-fragments.d.mts +4 -3
- package/esm/rules/no-one-place-fragments.js +12 -19
- package/esm/rules/no-root-type.d.mts +4 -3
- package/esm/rules/no-root-type.js +11 -18
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
- package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
- package/esm/rules/no-typename-prefix.d.mts +4 -3
- package/esm/rules/no-typename-prefix.js +22 -26
- package/esm/rules/no-unreachable-types.d.mts +4 -3
- package/esm/rules/no-unreachable-types.js +18 -33
- package/esm/rules/no-unused-fields.d.mts +4 -3
- package/esm/rules/no-unused-fields.js +19 -40
- package/esm/rules/relay-arguments.d.mts +4 -3
- package/esm/rules/relay-arguments.js +15 -34
- package/esm/rules/relay-connection-types.d.mts +4 -3
- package/esm/rules/relay-connection-types.js +10 -38
- package/esm/rules/relay-edge-types.d.mts +4 -3
- package/esm/rules/relay-edge-types.js +43 -89
- package/esm/rules/relay-page-info.d.mts +4 -3
- package/esm/rules/relay-page-info.js +16 -34
- package/esm/rules/require-deprecation-date.d.mts +4 -3
- package/esm/rules/require-deprecation-date.js +10 -22
- package/esm/rules/require-deprecation-reason.d.mts +4 -3
- package/esm/rules/require-deprecation-reason.js +7 -11
- package/esm/rules/require-description.d.mts +4 -3
- package/esm/rules/require-description.js +34 -55
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
- package/esm/rules/require-import-fragment.d.mts +4 -3
- package/esm/rules/require-import-fragment.js +14 -26
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
- package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
- package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
- package/esm/rules/require-nullable-result-in-root.js +29 -35
- package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
- package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
- package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
- package/esm/rules/require-type-pattern-with-oneof.js +11 -16
- package/esm/rules/selection-set-depth.d.mts +4 -3
- package/esm/rules/selection-set-depth.js +11 -20
- package/esm/rules/strict-id-in-types.d.mts +4 -3
- package/esm/rules/strict-id-in-types.js +20 -34
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
- package/esm/rules/unique-fragment-name.d.mts +3 -2
- package/esm/rules/unique-fragment-name.js +20 -27
- package/esm/rules/unique-operation-name.d.mts +4 -3
- package/esm/rules/unique-operation-name.js +6 -5
- package/esm/schema.d.mts +4 -3
- package/esm/schema.js +7 -12
- package/esm/siblings.d.mts +24 -8
- package/esm/siblings.js +37 -73
- package/esm/types.d.mts +74 -7
- package/esm/utils.d.mts +3 -2
- package/esm/utils.js +20 -31
- package/index.browser.mjs +5323 -0
- package/package.json +8 -13
- package/cjs/rules/require-id-when-available.js +0 -241
- package/cjs/types-8d5f4ae0.d.ts +0 -107
- package/esm/types-ace77d86.d.ts +0 -107
- /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
- /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
- /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
package/esm/processor.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import "./chunk-
|
2
|
-
import { relative } from "path";
|
1
|
+
import "./chunk-U3TKCM4X.js";
|
2
|
+
import { relative } from "node:path";
|
3
3
|
import {
|
4
4
|
gqlPluckFromCodeStringSync
|
5
5
|
} from "@graphql-tools/graphql-tag-pluck";
|
@@ -7,18 +7,13 @@ import { asArray } from "@graphql-tools/utils";
|
|
7
7
|
import { loadOnDiskGraphQLConfig } from "./graphql-config.js";
|
8
8
|
import { CWD, REPORT_ON_FIRST_CHARACTER, truthy } from "./utils.js";
|
9
9
|
const blocksMap = /* @__PURE__ */ new Map();
|
10
|
-
let onDiskConfig;
|
11
|
-
|
12
|
-
|
13
|
-
const processor = {
|
14
|
-
supportsAutofix: true,
|
10
|
+
let onDiskConfig, onDiskConfigLoaded = !1;
|
11
|
+
const RELEVANT_KEYWORDS = ["gql", "graphql", "GraphQL"], processor = {
|
12
|
+
supportsAutofix: !0,
|
15
13
|
preprocess(code, filePath) {
|
16
|
-
|
17
|
-
onDiskConfig = loadOnDiskGraphQLConfig(filePath);
|
18
|
-
onDiskConfigLoaded = true;
|
19
|
-
}
|
14
|
+
onDiskConfigLoaded || (onDiskConfig = loadOnDiskGraphQLConfig(filePath), onDiskConfigLoaded = !0);
|
20
15
|
let keywords = RELEVANT_KEYWORDS;
|
21
|
-
const pluckConfig = onDiskConfig
|
16
|
+
const pluckConfig = onDiskConfig?.getProjectForFile(filePath).extensions.pluckConfig;
|
22
17
|
if (pluckConfig) {
|
23
18
|
const {
|
24
19
|
modules = [],
|
@@ -35,38 +30,31 @@ const processor = {
|
|
35
30
|
)
|
36
31
|
];
|
37
32
|
}
|
38
|
-
if (keywords.every((keyword) => !code.includes(keyword)))
|
33
|
+
if (keywords.every((keyword) => !code.includes(keyword)))
|
39
34
|
return [code];
|
40
|
-
}
|
41
35
|
try {
|
42
|
-
const
|
43
|
-
skipIndent:
|
36
|
+
const blocks = gqlPluckFromCodeStringSync(filePath, code, {
|
37
|
+
skipIndent: !0,
|
44
38
|
...pluckConfig
|
45
|
-
})
|
46
|
-
const blocks = sources.map((item) => ({
|
39
|
+
}).map((item) => ({
|
47
40
|
filename: "document.graphql",
|
48
41
|
text: item.body,
|
49
42
|
lineOffset: item.locationOffset.line - 1,
|
50
43
|
// @ts-expect-error -- `index` field exist but show ts error
|
51
44
|
offset: item.locationOffset.index + 1
|
52
45
|
}));
|
53
|
-
blocksMap.set(filePath, blocks)
|
54
|
-
return [
|
46
|
+
return blocksMap.set(filePath, blocks), [
|
55
47
|
...blocks,
|
56
48
|
code
|
57
49
|
/* source code must be provided and be last */
|
58
50
|
];
|
59
51
|
} catch (error) {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
)}" file
|
52
|
+
return error instanceof Error && (error.message = `[graphql-eslint] Error while preprocessing "${relative(
|
53
|
+
CWD,
|
54
|
+
filePath
|
55
|
+
)}" file
|
65
56
|
|
66
|
-
${error.message}
|
67
|
-
}
|
68
|
-
console.error(error);
|
69
|
-
return [code];
|
57
|
+
${error.message}`), console.error(error), [code];
|
70
58
|
}
|
71
59
|
},
|
72
60
|
postprocess(messages, filePath) {
|
@@ -74,31 +62,18 @@ ${error.message}`;
|
|
74
62
|
for (let i = 0; i < blocks.length; i += 1) {
|
75
63
|
const { lineOffset, offset } = blocks[i];
|
76
64
|
for (const message of messages[i] || []) {
|
77
|
-
|
78
|
-
|
79
|
-
delete message.endLine;
|
80
|
-
delete message.endColumn;
|
81
|
-
delete message.fix;
|
82
|
-
delete message.suggestions;
|
83
|
-
Object.assign(message, REPORT_ON_FIRST_CHARACTER);
|
65
|
+
if (/\.(vue|svelte)$/.test(filePath)) {
|
66
|
+
delete message.endLine, delete message.endColumn, delete message.fix, delete message.suggestions, Object.assign(message, REPORT_ON_FIRST_CHARACTER);
|
84
67
|
continue;
|
85
68
|
}
|
86
|
-
message.line += lineOffset;
|
87
|
-
if (typeof message.endLine === "number") {
|
88
|
-
message.endLine += lineOffset;
|
89
|
-
}
|
90
|
-
if (message.fix) {
|
91
|
-
message.fix.range[0] += offset;
|
92
|
-
message.fix.range[1] += offset;
|
93
|
-
}
|
69
|
+
message.line += lineOffset, typeof message.endLine == "number" && (message.endLine += lineOffset), message.fix && (message.fix.range[0] += offset, message.fix.range[1] += offset);
|
94
70
|
for (const suggestion of message.suggestions || []) {
|
95
71
|
const [start, end] = suggestion.fix.range;
|
96
72
|
suggestion.fix.range = [start + offset, end + offset];
|
97
73
|
}
|
98
74
|
}
|
99
75
|
}
|
100
|
-
|
101
|
-
return result.sort((a, b) => a.line - b.line || a.column - b.column);
|
76
|
+
return messages.flat().sort((a, b) => a.line - b.line || a.column - b.column);
|
102
77
|
}
|
103
78
|
};
|
104
79
|
export {
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FromSchema } from 'json-schema-to-ts';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
5
|
import 'graphql';
|
7
|
-
import '
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const schema: {
|
11
12
|
readonly type: "array";
|
@@ -26,13 +27,8 @@ declare const schema: {
|
|
26
27
|
readonly minItems: 1;
|
27
28
|
};
|
28
29
|
readonly values: {
|
29
|
-
readonly
|
30
|
-
readonly enum: ["EnumTypeDefinition"];
|
31
|
-
};
|
30
|
+
readonly type: "boolean";
|
32
31
|
readonly description: "Values of `enum`.";
|
33
|
-
readonly type: "array";
|
34
|
-
readonly uniqueItems: true;
|
35
|
-
readonly minItems: 1;
|
36
32
|
};
|
37
33
|
readonly selections: {
|
38
34
|
readonly items: {
|
@@ -44,13 +40,8 @@ declare const schema: {
|
|
44
40
|
readonly minItems: 1;
|
45
41
|
};
|
46
42
|
readonly variables: {
|
47
|
-
readonly
|
48
|
-
readonly enum: ["OperationDefinition"];
|
49
|
-
};
|
43
|
+
readonly type: "boolean";
|
50
44
|
readonly description: "Variables of operations `query`, `mutation` and `subscription`.";
|
51
|
-
readonly type: "array";
|
52
|
-
readonly uniqueItems: true;
|
53
|
-
readonly minItems: 1;
|
54
45
|
};
|
55
46
|
readonly arguments: {
|
56
47
|
readonly items: {
|
@@ -64,7 +55,6 @@ declare const schema: {
|
|
64
55
|
readonly definitions: {
|
65
56
|
readonly type: "boolean";
|
66
57
|
readonly description: "Definitions – `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`.";
|
67
|
-
readonly default: false;
|
68
58
|
};
|
69
59
|
readonly groups: {
|
70
60
|
readonly minItems: 2;
|
package/esm/rules/alphabetize.js
CHANGED
@@ -1,34 +1,28 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import {
|
3
3
|
Kind
|
4
4
|
} from "graphql";
|
5
5
|
import lowerCase from "lodash.lowercase";
|
6
6
|
import { ARRAY_DEFAULT_OPTIONS, displayNodeName, truthy } from "../utils.js";
|
7
|
-
const RULE_ID = "alphabetize"
|
8
|
-
const fieldsEnum = [
|
7
|
+
const RULE_ID = "alphabetize", fieldsEnum = [
|
9
8
|
Kind.OBJECT_TYPE_DEFINITION,
|
10
9
|
Kind.INTERFACE_TYPE_DEFINITION,
|
11
10
|
Kind.INPUT_OBJECT_TYPE_DEFINITION
|
12
|
-
]
|
13
|
-
const valuesEnum = [Kind.ENUM_TYPE_DEFINITION];
|
14
|
-
const selectionsEnum = [
|
11
|
+
], selectionsEnum = [
|
15
12
|
Kind.OPERATION_DEFINITION,
|
16
13
|
Kind.FRAGMENT_DEFINITION
|
17
|
-
]
|
18
|
-
const variablesEnum = [Kind.OPERATION_DEFINITION];
|
19
|
-
const argumentsEnum = [
|
14
|
+
], argumentsEnum = [
|
20
15
|
Kind.FIELD_DEFINITION,
|
21
16
|
Kind.FIELD,
|
22
17
|
Kind.DIRECTIVE_DEFINITION,
|
23
18
|
Kind.DIRECTIVE
|
24
|
-
]
|
25
|
-
const schema = {
|
19
|
+
], schema = {
|
26
20
|
type: "array",
|
27
21
|
minItems: 1,
|
28
22
|
maxItems: 1,
|
29
23
|
items: {
|
30
24
|
type: "object",
|
31
|
-
additionalProperties:
|
25
|
+
additionalProperties: !1,
|
32
26
|
minProperties: 1,
|
33
27
|
properties: {
|
34
28
|
fields: {
|
@@ -39,10 +33,7 @@ const schema = {
|
|
39
33
|
description: "Fields of `type`, `interface`, and `input`."
|
40
34
|
},
|
41
35
|
values: {
|
42
|
-
|
43
|
-
items: {
|
44
|
-
enum: valuesEnum
|
45
|
-
},
|
36
|
+
type: "boolean",
|
46
37
|
description: "Values of `enum`."
|
47
38
|
},
|
48
39
|
selections: {
|
@@ -53,10 +44,7 @@ const schema = {
|
|
53
44
|
description: "Selections of `fragment` and operations `query`, `mutation` and `subscription`."
|
54
45
|
},
|
55
46
|
variables: {
|
56
|
-
|
57
|
-
items: {
|
58
|
-
enum: variablesEnum
|
59
|
-
},
|
47
|
+
type: "boolean",
|
60
48
|
description: "Variables of operations `query`, `mutation` and `subscription`."
|
61
49
|
},
|
62
50
|
arguments: {
|
@@ -68,8 +56,7 @@ const schema = {
|
|
68
56
|
},
|
69
57
|
definitions: {
|
70
58
|
type: "boolean",
|
71
|
-
description: "Definitions \u2013 `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`."
|
72
|
-
default: false
|
59
|
+
description: "Definitions \u2013 `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`."
|
73
60
|
},
|
74
61
|
groups: {
|
75
62
|
...ARRAY_DEFAULT_OPTIONS,
|
@@ -78,8 +65,7 @@ const schema = {
|
|
78
65
|
}
|
79
66
|
}
|
80
67
|
}
|
81
|
-
}
|
82
|
-
const rule = {
|
68
|
+
}, rule = {
|
83
69
|
meta: {
|
84
70
|
type: "suggestion",
|
85
71
|
fixable: "code",
|
@@ -120,7 +106,7 @@ const rule = {
|
|
120
106
|
},
|
121
107
|
{
|
122
108
|
title: "Incorrect",
|
123
|
-
usage: [{ values:
|
109
|
+
usage: [{ values: !0 }],
|
124
110
|
code: (
|
125
111
|
/* GraphQL */
|
126
112
|
`
|
@@ -135,7 +121,7 @@ const rule = {
|
|
135
121
|
},
|
136
122
|
{
|
137
123
|
title: "Correct",
|
138
|
-
usage: [{ values:
|
124
|
+
usage: [{ values: !0 }],
|
139
125
|
code: (
|
140
126
|
/* GraphQL */
|
141
127
|
`
|
@@ -184,19 +170,20 @@ const rule = {
|
|
184
170
|
configOptions: {
|
185
171
|
schema: [
|
186
172
|
{
|
173
|
+
definitions: !0,
|
187
174
|
fields: fieldsEnum,
|
188
|
-
values:
|
189
|
-
arguments: argumentsEnum
|
190
|
-
|
191
|
-
// definitions: true,
|
192
|
-
// groups: ['id', '*', 'createdAt', 'updatedAt']
|
175
|
+
values: !0,
|
176
|
+
arguments: argumentsEnum,
|
177
|
+
groups: ["id", "*", "createdAt", "updatedAt"]
|
193
178
|
}
|
194
179
|
],
|
195
180
|
operations: [
|
196
181
|
{
|
182
|
+
definitions: !0,
|
197
183
|
selections: selectionsEnum,
|
198
|
-
variables:
|
199
|
-
arguments: [Kind.FIELD, Kind.DIRECTIVE]
|
184
|
+
variables: !0,
|
185
|
+
arguments: [Kind.FIELD, Kind.DIRECTIVE],
|
186
|
+
groups: ["id", "*", "createdAt", "updatedAt"]
|
200
187
|
}
|
201
188
|
]
|
202
189
|
}
|
@@ -207,77 +194,51 @@ const rule = {
|
|
207
194
|
schema
|
208
195
|
},
|
209
196
|
create(context) {
|
210
|
-
var _a, _b, _c, _d, _e;
|
211
197
|
const sourceCode = context.getSourceCode();
|
212
198
|
function isNodeAndCommentOnSameLine(node, comment) {
|
213
199
|
return node.loc.end.line === comment.loc.start.line;
|
214
200
|
}
|
215
201
|
function getBeforeComments(node) {
|
216
202
|
const commentsBefore = sourceCode.getCommentsBefore(node);
|
217
|
-
if (commentsBefore.length === 0)
|
203
|
+
if (commentsBefore.length === 0)
|
218
204
|
return [];
|
219
|
-
}
|
220
205
|
const tokenBefore = sourceCode.getTokenBefore(node);
|
221
|
-
if (tokenBefore)
|
206
|
+
if (tokenBefore)
|
222
207
|
return commentsBefore.filter((comment) => !isNodeAndCommentOnSameLine(tokenBefore, comment));
|
223
|
-
|
224
|
-
const filteredComments = [];
|
225
|
-
const nodeLine = node.loc.start.line;
|
208
|
+
const filteredComments = [], nodeLine = node.loc.start.line;
|
226
209
|
for (let i = commentsBefore.length - 1; i >= 0; i -= 1) {
|
227
210
|
const comment = commentsBefore[i];
|
228
|
-
if (nodeLine - comment.loc.start.line - filteredComments.length > 1)
|
211
|
+
if (nodeLine - comment.loc.start.line - filteredComments.length > 1)
|
229
212
|
break;
|
230
|
-
}
|
231
213
|
filteredComments.unshift(comment);
|
232
214
|
}
|
233
215
|
return filteredComments;
|
234
216
|
}
|
235
217
|
function getRangeWithComments(node) {
|
236
|
-
|
237
|
-
|
238
|
-
}
|
239
|
-
const [firstBeforeComment] = getBeforeComments(node);
|
240
|
-
const [firstAfterComment] = sourceCode.getCommentsAfter(node);
|
241
|
-
const from = firstBeforeComment || node;
|
242
|
-
const to = firstAfterComment && isNodeAndCommentOnSameLine(node, firstAfterComment) ? firstAfterComment : node;
|
218
|
+
node.kind === Kind.VARIABLE && (node = node.parent);
|
219
|
+
const [firstBeforeComment] = getBeforeComments(node), [firstAfterComment] = sourceCode.getCommentsAfter(node), from = firstBeforeComment || node, to = firstAfterComment && isNodeAndCommentOnSameLine(node, firstAfterComment) ? firstAfterComment : node;
|
243
220
|
return [from.range[0], to.range[1]];
|
244
221
|
}
|
245
222
|
function checkNodes(nodes = []) {
|
246
|
-
var _a2, _b2, _c2, _d2;
|
247
223
|
for (let i = 1; i < nodes.length; i += 1) {
|
248
|
-
const currNode = nodes[i];
|
249
|
-
|
250
|
-
if (!currName) {
|
224
|
+
const currNode = nodes[i], currName = "alias" in currNode && currNode.alias?.value || "name" in currNode && currNode.name?.value;
|
225
|
+
if (!currName)
|
251
226
|
continue;
|
252
|
-
|
253
|
-
const prevNode = nodes[i - 1];
|
254
|
-
const prevName = "alias" in prevNode && ((_c2 = prevNode.alias) == null ? void 0 : _c2.value) || "name" in prevNode && ((_d2 = prevNode.name) == null ? void 0 : _d2.value);
|
227
|
+
const prevNode = nodes[i - 1], prevName = "alias" in prevNode && prevNode.alias?.value || "name" in prevNode && prevNode.name?.value;
|
255
228
|
if (prevName) {
|
256
|
-
const compareResult = prevName.localeCompare(currName);
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
if (!groups.includes("*")) {
|
229
|
+
const compareResult = prevName.localeCompare(currName), { groups } = opts;
|
230
|
+
let shouldSortByGroup = !1;
|
231
|
+
if (groups?.length) {
|
232
|
+
if (!groups.includes("*"))
|
261
233
|
throw new Error("`groups` option should contain `*` string.");
|
262
|
-
}
|
263
234
|
let indexForPrev = groups.indexOf(prevName);
|
264
|
-
|
265
|
-
indexForPrev = groups.indexOf("*");
|
235
|
+
indexForPrev === -1 && (indexForPrev = groups.indexOf("*"));
|
266
236
|
let indexForCurr = groups.indexOf(currName);
|
267
|
-
if (indexForCurr === -1)
|
268
|
-
indexForCurr = groups.indexOf("*");
|
269
|
-
shouldSortByGroup = indexForPrev - indexForCurr > 0;
|
270
|
-
if (indexForPrev < indexForCurr) {
|
237
|
+
if (indexForCurr === -1 && (indexForCurr = groups.indexOf("*")), shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
271
238
|
continue;
|
272
|
-
}
|
273
|
-
}
|
274
|
-
const shouldSort = compareResult === 1;
|
275
|
-
if (!shouldSortByGroup && !shouldSort) {
|
276
|
-
const isSameName = compareResult === 0;
|
277
|
-
if (!isSameName || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")) {
|
278
|
-
continue;
|
279
|
-
}
|
280
239
|
}
|
240
|
+
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
241
|
+
continue;
|
281
242
|
}
|
282
243
|
context.report({
|
283
244
|
// @ts-expect-error can't be undefined
|
@@ -288,13 +249,11 @@ const rule = {
|
|
288
249
|
prevNode: prevName ? displayNodeName(prevNode) : lowerCase(prevNode.kind)
|
289
250
|
},
|
290
251
|
*fix(fixer) {
|
291
|
-
const prevRange = getRangeWithComments(prevNode);
|
292
|
-
const currRange = getRangeWithComments(currNode);
|
252
|
+
const prevRange = getRangeWithComments(prevNode), currRange = getRangeWithComments(currNode);
|
293
253
|
yield fixer.replaceTextRange(
|
294
254
|
prevRange,
|
295
255
|
sourceCode.getText({ range: currRange })
|
296
|
-
)
|
297
|
-
yield fixer.replaceTextRange(
|
256
|
+
), yield fixer.replaceTextRange(
|
298
257
|
currRange,
|
299
258
|
sourceCode.getText({ range: prevRange })
|
300
259
|
);
|
@@ -302,10 +261,7 @@ const rule = {
|
|
302
261
|
});
|
303
262
|
}
|
304
263
|
}
|
305
|
-
const opts = context.options[0]
|
306
|
-
const fields = new Set((_a = opts.fields) != null ? _a : []);
|
307
|
-
const listeners = {};
|
308
|
-
const kinds = [
|
264
|
+
const opts = context.options[0], fields = new Set(opts.fields ?? []), listeners = {}, fieldsSelector = [
|
309
265
|
fields.has(Kind.OBJECT_TYPE_DEFINITION) && [
|
310
266
|
Kind.OBJECT_TYPE_DEFINITION,
|
311
267
|
Kind.OBJECT_TYPE_EXTENSION
|
@@ -318,45 +274,24 @@ const rule = {
|
|
318
274
|
Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
319
275
|
Kind.INPUT_OBJECT_TYPE_EXTENSION
|
320
276
|
]
|
321
|
-
].filter(truthy).flat();
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
const hasVariables = ((_d = opts.variables) == null ? void 0 : _d[0]) === Kind.OPERATION_DEFINITION;
|
326
|
-
const argumentsSelector = (_e = opts.arguments) == null ? void 0 : _e.join(",");
|
327
|
-
if (fieldsSelector) {
|
328
|
-
listeners[fieldsSelector] = (node) => {
|
329
|
-
checkNodes(node.fields);
|
330
|
-
};
|
331
|
-
}
|
332
|
-
if (hasEnumValues) {
|
277
|
+
].filter(truthy).flat().join(","), selectionsSelector = opts.selections?.join(","), argumentsSelector = opts.arguments?.join(",");
|
278
|
+
if (fieldsSelector && (listeners[fieldsSelector] = (node) => {
|
279
|
+
checkNodes(node.fields);
|
280
|
+
}), opts.values) {
|
333
281
|
const enumValuesSelector = [Kind.ENUM_TYPE_DEFINITION, Kind.ENUM_TYPE_EXTENSION].join(",");
|
334
282
|
listeners[enumValuesSelector] = (node) => {
|
335
283
|
checkNodes(node.values);
|
336
284
|
};
|
337
285
|
}
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
}
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
};
|
348
|
-
}
|
349
|
-
if (argumentsSelector) {
|
350
|
-
listeners[argumentsSelector] = (node) => {
|
351
|
-
checkNodes(node.arguments);
|
352
|
-
};
|
353
|
-
}
|
354
|
-
if (opts.definitions) {
|
355
|
-
listeners.Document = (node) => {
|
356
|
-
checkNodes(node.definitions);
|
357
|
-
};
|
358
|
-
}
|
359
|
-
return listeners;
|
286
|
+
return selectionsSelector && (listeners[`:matches(${selectionsSelector}) SelectionSet`] = (node) => {
|
287
|
+
checkNodes(node.selections);
|
288
|
+
}), opts.variables && (listeners.OperationDefinition = (node) => {
|
289
|
+
checkNodes(node.variableDefinitions?.map((varDef) => varDef.variable));
|
290
|
+
}), argumentsSelector && (listeners[argumentsSelector] = (node) => {
|
291
|
+
checkNodes(node.arguments);
|
292
|
+
}), opts.definitions && (listeners.Document = (node) => {
|
293
|
+
checkNodes(node.definitions);
|
294
|
+
}), listeners;
|
360
295
|
}
|
361
296
|
};
|
362
297
|
export {
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FromSchema } from 'json-schema-to-ts';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
5
|
import 'graphql';
|
7
|
-
import '
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const schema: {
|
11
12
|
readonly type: "array";
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { getNodeName } from "../utils.js";
|
3
3
|
const schema = {
|
4
4
|
type: "array",
|
5
5
|
maxItems: 1,
|
6
6
|
items: {
|
7
7
|
type: "object",
|
8
|
-
additionalProperties:
|
8
|
+
additionalProperties: !1,
|
9
9
|
minProperties: 1,
|
10
10
|
properties: {
|
11
11
|
style: {
|
@@ -14,11 +14,10 @@ const schema = {
|
|
14
14
|
}
|
15
15
|
}
|
16
16
|
}
|
17
|
-
}
|
18
|
-
const rule = {
|
17
|
+
}, rule = {
|
19
18
|
meta: {
|
20
19
|
type: "suggestion",
|
21
|
-
hasSuggestions:
|
20
|
+
hasSuggestions: !0,
|
22
21
|
docs: {
|
23
22
|
examples: [
|
24
23
|
{
|
@@ -51,13 +50,12 @@ const rule = {
|
|
51
50
|
description: "Require all comments to follow the same style (either block or inline).",
|
52
51
|
category: "Schema",
|
53
52
|
url: "https://the-guild.dev/graphql/eslint/rules/description-style",
|
54
|
-
recommended:
|
53
|
+
recommended: !0
|
55
54
|
},
|
56
55
|
schema
|
57
56
|
},
|
58
57
|
create(context) {
|
59
|
-
const { style = "block" } = context.options[0] || {};
|
60
|
-
const isBlock = style === "block";
|
58
|
+
const { style = "block" } = context.options[0] || {}, isBlock = style === "block";
|
61
59
|
return {
|
62
60
|
[`.description[type=StringValue][block!=${isBlock}]`](node) {
|
63
61
|
context.report({
|
@@ -69,9 +67,7 @@ const rule = {
|
|
69
67
|
{
|
70
68
|
desc: `Change to ${isBlock ? "block" : "inline"} style description`,
|
71
69
|
fix(fixer) {
|
72
|
-
const
|
73
|
-
const originalText = sourceCode.getText(node);
|
74
|
-
const newText = isBlock ? originalText.replace(/(^")|("$)/g, '"""') : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, " ");
|
70
|
+
const originalText = context.getSourceCode().getText(node), newText = isBlock ? originalText.replace(/(^")|("$)/g, '"""') : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, " ");
|
75
71
|
return fixer.replaceText(node, newText);
|
76
72
|
}
|
77
73
|
}
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
3
2
|
import 'eslint';
|
4
3
|
import 'estree';
|
5
4
|
import 'graphql';
|
6
|
-
import 'graphql-config';
|
7
5
|
import 'json-schema-to-ts';
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const GRAPHQL_JS_VALIDATIONS: Record<string, GraphQLESLintRule>;
|
11
12
|
|