@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810160036-304c2c0
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
@@ -1,4 +1,4 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
3
|
import {
|
4
4
|
ARRAY_DEFAULT_OPTIONS,
|
@@ -25,19 +25,14 @@ const KindToDisplayName = {
|
|
25
25
|
[Kind.OPERATION_DEFINITION]: "Operation",
|
26
26
|
[Kind.FRAGMENT_DEFINITION]: "Fragment",
|
27
27
|
[Kind.VARIABLE_DEFINITION]: "Variable"
|
28
|
-
}
|
29
|
-
const StyleToRegex = {
|
28
|
+
}, StyleToRegex = {
|
30
29
|
camelCase: /^[a-z][\dA-Za-z]*$/,
|
31
30
|
PascalCase: /^[A-Z][\dA-Za-z]*$/,
|
32
31
|
snake_case: /^[a-z][\d_a-z]*[\da-z]*$/,
|
33
32
|
UPPER_CASE: /^[A-Z][\dA-Z_]*[\dA-Z]*$/
|
34
|
-
}
|
35
|
-
const ALLOWED_KINDS = Object.keys(KindToDisplayName).sort();
|
36
|
-
const ALLOWED_STYLES = Object.keys(StyleToRegex);
|
37
|
-
const schemaOption = {
|
33
|
+
}, ALLOWED_KINDS = Object.keys(KindToDisplayName).sort(), ALLOWED_STYLES = Object.keys(StyleToRegex), schemaOption = {
|
38
34
|
oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asObject" }]
|
39
|
-
}
|
40
|
-
const schema = {
|
35
|
+
}, schema = {
|
41
36
|
definitions: {
|
42
37
|
asString: {
|
43
38
|
enum: ALLOWED_STYLES,
|
@@ -45,7 +40,7 @@ const schema = {
|
|
45
40
|
},
|
46
41
|
asObject: {
|
47
42
|
type: "object",
|
48
|
-
additionalProperties:
|
43
|
+
additionalProperties: !1,
|
49
44
|
properties: {
|
50
45
|
style: { enum: ALLOWED_STYLES },
|
51
46
|
prefix: { type: "string" },
|
@@ -65,12 +60,13 @@ const schema = {
|
|
65
60
|
maxItems: 1,
|
66
61
|
items: {
|
67
62
|
type: "object",
|
68
|
-
additionalProperties:
|
63
|
+
additionalProperties: !1,
|
69
64
|
properties: {
|
70
65
|
types: {
|
71
66
|
...schemaOption,
|
72
67
|
description: `Includes:
|
73
|
-
${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(
|
68
|
+
${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
|
69
|
+
`)}`
|
74
70
|
},
|
75
71
|
...Object.fromEntries(
|
76
72
|
ALLOWED_KINDS.map((kind) => [
|
@@ -83,11 +79,11 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
|
|
83
79
|
),
|
84
80
|
allowLeadingUnderscore: {
|
85
81
|
type: "boolean",
|
86
|
-
default:
|
82
|
+
default: !1
|
87
83
|
},
|
88
84
|
allowTrailingUnderscore: {
|
89
85
|
type: "boolean",
|
90
|
-
default:
|
86
|
+
default: !1
|
91
87
|
}
|
92
88
|
},
|
93
89
|
patternProperties: {
|
@@ -99,16 +95,16 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
|
|
99
95
|
"> Paste or drop code into the editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your selector.",
|
100
96
|
">",
|
101
97
|
"> Example: pattern property `FieldDefinition[parent.name.value=Query]` will match only fields for type `Query`."
|
102
|
-
].join(
|
98
|
+
].join(`
|
99
|
+
`)
|
103
100
|
}
|
104
|
-
}
|
105
|
-
const rule = {
|
101
|
+
}, rule = {
|
106
102
|
meta: {
|
107
103
|
type: "suggestion",
|
108
104
|
docs: {
|
109
105
|
description: "Require names to follow specified conventions.",
|
110
106
|
category: ["Schema", "Operations"],
|
111
|
-
recommended:
|
107
|
+
recommended: !0,
|
112
108
|
url: "https://the-guild.dev/graphql/eslint/rules/naming-convention",
|
113
109
|
examples: [
|
114
110
|
{
|
@@ -264,6 +260,22 @@ const rule = {
|
|
264
260
|
"FieldDefinition[parent.name.value=Subscription]": {
|
265
261
|
forbiddenPrefixes: ["subscription"],
|
266
262
|
forbiddenSuffixes: ["Subscription"]
|
263
|
+
},
|
264
|
+
"EnumTypeDefinition,EnumTypeExtension": {
|
265
|
+
forbiddenPrefixes: ["Enum"],
|
266
|
+
forbiddenSuffixes: ["Enum"]
|
267
|
+
},
|
268
|
+
"InterfaceTypeDefinition,InterfaceTypeExtension": {
|
269
|
+
forbiddenPrefixes: ["Interface"],
|
270
|
+
forbiddenSuffixes: ["Interface"]
|
271
|
+
},
|
272
|
+
"UnionTypeDefinition,UnionTypeExtension": {
|
273
|
+
forbiddenPrefixes: ["Union"],
|
274
|
+
forbiddenSuffixes: ["Union"]
|
275
|
+
},
|
276
|
+
"ObjectTypeDefinition,ObjectTypeExtension": {
|
277
|
+
forbiddenPrefixes: ["Type"],
|
278
|
+
forbiddenSuffixes: ["Type"]
|
267
279
|
}
|
268
280
|
}
|
269
281
|
],
|
@@ -284,15 +296,14 @@ const rule = {
|
|
284
296
|
]
|
285
297
|
}
|
286
298
|
},
|
287
|
-
hasSuggestions:
|
299
|
+
hasSuggestions: !0,
|
288
300
|
schema
|
289
301
|
},
|
290
302
|
create(context) {
|
291
|
-
const options = context.options[0] || {};
|
292
|
-
const { allowLeadingUnderscore, allowTrailingUnderscore, types, ...restOptions } = options;
|
303
|
+
const options = context.options[0] || {}, { allowLeadingUnderscore, allowTrailingUnderscore, types, ...restOptions } = options;
|
293
304
|
function normalisePropertyOption(kind) {
|
294
305
|
const style = restOptions[kind] || types;
|
295
|
-
return typeof style
|
306
|
+
return typeof style == "object" ? style : { style };
|
296
307
|
}
|
297
308
|
function report(node, message, suggestedNames) {
|
298
309
|
context.report({
|
@@ -306,9 +317,8 @@ const rule = {
|
|
306
317
|
}
|
307
318
|
const checkNode = (selector) => (n) => {
|
308
319
|
const { name: node } = n.kind === Kind.VARIABLE_DEFINITION ? n.variable : n;
|
309
|
-
if (!node)
|
320
|
+
if (!node)
|
310
321
|
return;
|
311
|
-
}
|
312
322
|
const {
|
313
323
|
prefix,
|
314
324
|
suffix,
|
@@ -318,97 +328,73 @@ const rule = {
|
|
318
328
|
ignorePattern,
|
319
329
|
requiredPrefixes,
|
320
330
|
requiredSuffixes
|
321
|
-
} = normalisePropertyOption(selector);
|
322
|
-
const nodeType = KindToDisplayName[n.kind] || n.kind;
|
323
|
-
const nodeName = node.value;
|
324
|
-
const error = getError();
|
331
|
+
} = normalisePropertyOption(selector), nodeType = KindToDisplayName[n.kind] || n.kind, nodeName = node.value, error = getError();
|
325
332
|
if (error) {
|
326
|
-
const { errorMessage, renameToNames } = error
|
327
|
-
const [leadingUnderscores] = nodeName.match(/^_*/);
|
328
|
-
const [trailingUnderscores] = nodeName.match(/_*$/);
|
329
|
-
const suggestedNames = renameToNames.map(
|
333
|
+
const { errorMessage, renameToNames } = error, [leadingUnderscores] = nodeName.match(/^_*/), [trailingUnderscores] = nodeName.match(/_*$/), suggestedNames = renameToNames.map(
|
330
334
|
(renameToName) => leadingUnderscores + renameToName + trailingUnderscores
|
331
335
|
);
|
332
336
|
report(node, `${nodeType} "${nodeName}" should ${errorMessage}`, suggestedNames);
|
333
337
|
}
|
334
338
|
function getError() {
|
335
339
|
const name = nodeName.replace(/(^_+)|(_+$)/g, "");
|
336
|
-
if (ignorePattern && new RegExp(ignorePattern, "u").test(name))
|
340
|
+
if (ignorePattern && new RegExp(ignorePattern, "u").test(name))
|
337
341
|
return;
|
338
|
-
|
339
|
-
if (prefix && !name.startsWith(prefix)) {
|
342
|
+
if (prefix && !name.startsWith(prefix))
|
340
343
|
return {
|
341
344
|
errorMessage: `have "${prefix}" prefix`,
|
342
345
|
renameToNames: [prefix + name]
|
343
346
|
};
|
344
|
-
|
345
|
-
if (suffix && !name.endsWith(suffix)) {
|
347
|
+
if (suffix && !name.endsWith(suffix))
|
346
348
|
return {
|
347
349
|
errorMessage: `have "${suffix}" suffix`,
|
348
350
|
renameToNames: [name + suffix]
|
349
351
|
};
|
350
|
-
|
351
|
-
|
352
|
-
if (forbiddenPrefix) {
|
352
|
+
const forbiddenPrefix = forbiddenPrefixes?.find((prefix2) => name.startsWith(prefix2));
|
353
|
+
if (forbiddenPrefix)
|
353
354
|
return {
|
354
355
|
errorMessage: `not have "${forbiddenPrefix}" prefix`,
|
355
356
|
renameToNames: [name.replace(new RegExp(`^${forbiddenPrefix}`), "")]
|
356
357
|
};
|
357
|
-
|
358
|
-
|
359
|
-
if (forbiddenSuffix) {
|
358
|
+
const forbiddenSuffix = forbiddenSuffixes?.find((suffix2) => name.endsWith(suffix2));
|
359
|
+
if (forbiddenSuffix)
|
360
360
|
return {
|
361
361
|
errorMessage: `not have "${forbiddenSuffix}" suffix`,
|
362
362
|
renameToNames: [name.replace(new RegExp(`${forbiddenSuffix}$`), "")]
|
363
363
|
};
|
364
|
-
|
365
|
-
if (requiredPrefixes && !requiredPrefixes.some((requiredPrefix) => name.startsWith(requiredPrefix))) {
|
364
|
+
if (requiredPrefixes && !requiredPrefixes.some((requiredPrefix) => name.startsWith(requiredPrefix)))
|
366
365
|
return {
|
367
366
|
errorMessage: `have one of the following prefixes: ${englishJoinWords(
|
368
367
|
requiredPrefixes
|
369
368
|
)}`,
|
370
369
|
renameToNames: style ? requiredPrefixes.map((prefix2) => convertCase(style, `${prefix2} ${name}`)) : requiredPrefixes.map((prefix2) => `${prefix2}${name}`)
|
371
370
|
};
|
372
|
-
|
373
|
-
if (requiredSuffixes && !requiredSuffixes.some((requiredSuffix) => name.endsWith(requiredSuffix))) {
|
371
|
+
if (requiredSuffixes && !requiredSuffixes.some((requiredSuffix) => name.endsWith(requiredSuffix)))
|
374
372
|
return {
|
375
373
|
errorMessage: `have one of the following suffixes: ${englishJoinWords(
|
376
374
|
requiredSuffixes
|
377
375
|
)}`,
|
378
376
|
renameToNames: style ? requiredSuffixes.map((suffix2) => convertCase(style, `${name} ${suffix2}`)) : requiredSuffixes.map((suffix2) => `${name}${suffix2}`)
|
379
377
|
};
|
380
|
-
|
381
|
-
if (!style) {
|
378
|
+
if (!style)
|
382
379
|
return;
|
383
|
-
|
384
|
-
const caseRegex = StyleToRegex[style];
|
385
|
-
if (!caseRegex.test(name)) {
|
380
|
+
if (!StyleToRegex[style].test(name))
|
386
381
|
return {
|
387
382
|
errorMessage: `be in ${style} format`,
|
388
383
|
renameToNames: [convertCase(style, name)]
|
389
384
|
};
|
390
|
-
}
|
391
385
|
}
|
392
|
-
}
|
393
|
-
const checkUnderscore = (isLeading) => (node) => {
|
386
|
+
}, checkUnderscore = (isLeading) => (node) => {
|
394
387
|
const suggestedName = node.value.replace(isLeading ? /^_+/ : /_+$/, "");
|
395
388
|
report(node, `${isLeading ? "Leading" : "Trailing"} underscores are not allowed`, [
|
396
389
|
suggestedName
|
397
390
|
]);
|
398
|
-
};
|
399
|
-
|
400
|
-
if (!allowLeadingUnderscore) {
|
401
|
-
listeners["Name[value=/^_/]:matches([parent.kind!=Field], [parent.kind=Field][parent.alias])"] = checkUnderscore(true);
|
402
|
-
}
|
403
|
-
if (!allowTrailingUnderscore) {
|
404
|
-
listeners["Name[value=/_$/]:matches([parent.kind!=Field], [parent.kind=Field][parent.alias])"] = checkUnderscore(false);
|
405
|
-
}
|
391
|
+
}, listeners = {};
|
392
|
+
allowLeadingUnderscore || (listeners["Name[value=/^_/]:matches([parent.kind!=Field], [parent.kind=Field][parent.alias])"] = checkUnderscore(!0)), allowTrailingUnderscore || (listeners["Name[value=/_$/]:matches([parent.kind!=Field], [parent.kind=Field][parent.alias])"] = checkUnderscore(!1));
|
406
393
|
const selectors = new Set(
|
407
394
|
[types && TYPES_KINDS, Object.keys(restOptions)].flat().filter(truthy)
|
408
395
|
);
|
409
|
-
for (const selector of selectors)
|
396
|
+
for (const selector of selectors)
|
410
397
|
listeners[selector] = checkNode(selector);
|
411
|
-
}
|
412
398
|
return listeners;
|
413
399
|
}
|
414
400
|
};
|
@@ -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 rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,15 +1,14 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
3
|
import { getLocation } from "../utils.js";
|
4
|
-
const RULE_ID = "no-anonymous-operations"
|
5
|
-
const rule = {
|
4
|
+
const RULE_ID = "no-anonymous-operations", rule = {
|
6
5
|
meta: {
|
7
6
|
type: "suggestion",
|
8
|
-
hasSuggestions:
|
7
|
+
hasSuggestions: !0,
|
9
8
|
docs: {
|
10
9
|
category: "Operations",
|
11
10
|
description: "Require name for your GraphQL operations. This is useful since most GraphQL client libraries are using the operation name for caching purposes.",
|
12
|
-
recommended:
|
11
|
+
recommended: !0,
|
13
12
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
14
13
|
examples: [
|
15
14
|
{
|
@@ -44,8 +43,7 @@ const rule = {
|
|
44
43
|
create(context) {
|
45
44
|
return {
|
46
45
|
"OperationDefinition[name=undefined]"(node) {
|
47
|
-
const [firstSelection] = node.selectionSet.selections;
|
48
|
-
const suggestedName = firstSelection.kind === Kind.FIELD ? (firstSelection.alias || firstSelection.name).value : node.operation;
|
46
|
+
const [firstSelection] = node.selectionSet.selections, suggestedName = firstSelection.kind === Kind.FIELD ? (firstSelection.alias || firstSelection.name).value : node.operation;
|
49
47
|
context.report({
|
50
48
|
loc: getLocation(node.loc.start, node.operation),
|
51
49
|
messageId: RULE_ID,
|
@@ -56,8 +54,7 @@ const rule = {
|
|
56
54
|
{
|
57
55
|
desc: `Rename to \`${suggestedName}\``,
|
58
56
|
fix(fixer) {
|
59
|
-
const
|
60
|
-
const hasQueryKeyword = sourceCode.getText({ range: [node.range[0], node.range[0] + 1] }) !== "{";
|
57
|
+
const hasQueryKeyword = context.getSourceCode().getText({ range: [node.range[0], node.range[0] + 1] }) !== "{";
|
61
58
|
return fixer.insertTextAfterRange(
|
62
59
|
[node.range[0], node.range[0] + (hasQueryKeyword ? node.operation.length : 0)],
|
63
60
|
`${hasQueryKeyword ? "" : "query"} ${suggestedName}${hasQueryKeyword ? "" : " "}`
|
@@ -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 rule: GraphQLESLintRule<[], true>;
|
11
12
|
|
@@ -1,16 +1,15 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
3
|
import { requireGraphQLSchemaFromContext } from "../utils.js";
|
4
|
-
const RULE_ID = "no-deprecated"
|
5
|
-
const rule = {
|
4
|
+
const RULE_ID = "no-deprecated", rule = {
|
6
5
|
meta: {
|
7
6
|
type: "suggestion",
|
8
|
-
hasSuggestions:
|
7
|
+
hasSuggestions: !0,
|
9
8
|
docs: {
|
10
9
|
category: "Operations",
|
11
10
|
description: "Enforce that deprecated fields or enum values are not in use by operations.",
|
12
11
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
13
|
-
requiresSchema:
|
12
|
+
requiresSchema: !0,
|
14
13
|
examples: [
|
15
14
|
{
|
16
15
|
title: "Incorrect (field)",
|
@@ -82,7 +81,7 @@ const rule = {
|
|
82
81
|
)
|
83
82
|
}
|
84
83
|
],
|
85
|
-
recommended:
|
84
|
+
recommended: !0
|
86
85
|
},
|
87
86
|
messages: {
|
88
87
|
[RULE_ID]: "This {{ type }} is marked as deprecated in your GraphQL schema (reason: {{ reason }})"
|
@@ -92,8 +91,7 @@ const rule = {
|
|
92
91
|
create(context) {
|
93
92
|
requireGraphQLSchemaFromContext(RULE_ID, context);
|
94
93
|
function report(node, reason) {
|
95
|
-
const nodeName = node.kind === Kind.ENUM ? node.value : node.name.value;
|
96
|
-
const nodeType = node.kind === Kind.ENUM ? "enum value" : "field";
|
94
|
+
const nodeName = node.kind === Kind.ENUM ? node.value : node.name.value, nodeType = node.kind === Kind.ENUM ? "enum value" : "field";
|
97
95
|
context.report({
|
98
96
|
node,
|
99
97
|
messageId: RULE_ID,
|
@@ -111,20 +109,12 @@ const rule = {
|
|
111
109
|
}
|
112
110
|
return {
|
113
111
|
EnumValue(node) {
|
114
|
-
|
115
|
-
|
116
|
-
const reason = (_a = typeInfo.enumValue) == null ? void 0 : _a.deprecationReason;
|
117
|
-
if (reason) {
|
118
|
-
report(node, reason);
|
119
|
-
}
|
112
|
+
const reason = node.typeInfo().enumValue?.deprecationReason;
|
113
|
+
reason && report(node, reason);
|
120
114
|
},
|
121
115
|
Field(node) {
|
122
|
-
|
123
|
-
|
124
|
-
const reason = (_a = typeInfo.fieldDef) == null ? void 0 : _a.deprecationReason;
|
125
|
-
if (reason) {
|
126
|
-
report(node, reason);
|
127
|
-
}
|
116
|
+
const reason = node.typeInfo().fieldDef?.deprecationReason;
|
117
|
+
reason && report(node, reason);
|
128
118
|
}
|
129
119
|
};
|
130
120
|
}
|
@@ -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 rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,15 +1,14 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
|
-
const RULE_ID = "no-duplicate-fields"
|
4
|
-
const rule = {
|
3
|
+
const RULE_ID = "no-duplicate-fields", rule = {
|
5
4
|
meta: {
|
6
5
|
type: "suggestion",
|
7
|
-
hasSuggestions:
|
6
|
+
hasSuggestions: !0,
|
8
7
|
docs: {
|
9
8
|
description: "Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field.",
|
10
9
|
category: "Operations",
|
11
10
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
12
|
-
recommended:
|
11
|
+
recommended: !0,
|
13
12
|
examples: [
|
14
13
|
{
|
15
14
|
title: "Incorrect",
|
@@ -90,30 +89,24 @@ const rule = {
|
|
90
89
|
}
|
91
90
|
]
|
92
91
|
});
|
93
|
-
} else
|
92
|
+
} else
|
94
93
|
usedFields.add(fieldName);
|
95
|
-
}
|
96
94
|
}
|
97
95
|
return {
|
98
96
|
OperationDefinition(node) {
|
99
97
|
const set = /* @__PURE__ */ new Set();
|
100
|
-
for (const varDef of node.variableDefinitions || [])
|
98
|
+
for (const varDef of node.variableDefinitions || [])
|
101
99
|
checkNode(set, varDef.variable.name);
|
102
|
-
}
|
103
100
|
},
|
104
101
|
Field(node) {
|
105
102
|
const set = /* @__PURE__ */ new Set();
|
106
|
-
for (const arg of node.arguments || [])
|
103
|
+
for (const arg of node.arguments || [])
|
107
104
|
checkNode(set, arg.name);
|
108
|
-
}
|
109
105
|
},
|
110
106
|
SelectionSet(node) {
|
111
107
|
const set = /* @__PURE__ */ new Set();
|
112
|
-
for (const selection of node.selections)
|
113
|
-
|
114
|
-
checkNode(set, selection.alias || selection.name);
|
115
|
-
}
|
116
|
-
}
|
108
|
+
for (const selection of node.selections)
|
109
|
+
selection.kind === Kind.FIELD && checkNode(set, selection.alias || selection.name);
|
117
110
|
}
|
118
111
|
};
|
119
112
|
}
|
@@ -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 RULE_ID = "HASHTAG_COMMENT";
|
11
12
|
declare const rule: GraphQLESLintRule;
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { TokenKind } from "graphql";
|
3
3
|
import { getNodeName } from "../utils.js";
|
4
|
-
const RULE_ID = "HASHTAG_COMMENT"
|
5
|
-
const rule = {
|
4
|
+
const RULE_ID = "HASHTAG_COMMENT", rule = {
|
6
5
|
meta: {
|
7
6
|
type: "suggestion",
|
8
|
-
hasSuggestions:
|
7
|
+
hasSuggestions: !0,
|
9
8
|
schema: [],
|
10
9
|
messages: {
|
11
10
|
[RULE_ID]: 'Unexpected GraphQL descriptions as hashtag `#` for {{ nodeName }}.\nPrefer using `"""` for multiline, or `"` for a single line description.'
|
@@ -58,27 +57,21 @@ const rule = {
|
|
58
57
|
)
|
59
58
|
}
|
60
59
|
],
|
61
|
-
recommended:
|
60
|
+
recommended: !0
|
62
61
|
}
|
63
62
|
},
|
64
63
|
create(context) {
|
65
|
-
const selector = "Document[definitions.0.kind!=/^(OperationDefinition|FragmentDefinition)$/]";
|
66
64
|
return {
|
67
|
-
[
|
68
|
-
|
69
|
-
|
70
|
-
while (token) {
|
65
|
+
["Document[definitions.0.kind!=/^(OperationDefinition|FragmentDefinition)$/]"](node) {
|
66
|
+
let token = node.rawNode().loc.startToken;
|
67
|
+
for (; token; ) {
|
71
68
|
const { kind, prev, next, value, line, column } = token;
|
72
69
|
if (kind === TokenKind.COMMENT && prev && next) {
|
73
|
-
const isEslintComment = value.trimStart().startsWith("eslint");
|
74
|
-
const linesAfter = next.line - line;
|
70
|
+
const isEslintComment = value.trimStart().startsWith("eslint"), linesAfter = next.line - line;
|
75
71
|
if (!isEslintComment && line !== prev.line && next.kind === TokenKind.NAME && linesAfter < 2) {
|
76
|
-
const sourceCode = context.getSourceCode()
|
77
|
-
const { tokens } = sourceCode.ast;
|
78
|
-
const t = tokens.find(
|
72
|
+
const sourceCode = context.getSourceCode(), { tokens } = sourceCode.ast, t = tokens.find(
|
79
73
|
(token2) => token2.loc.start.line === next.line && token2.loc.start.column === next.column - 1
|
80
|
-
);
|
81
|
-
const nextNode = sourceCode.getNodeByRangeIndex(t.range[1] + 1);
|
74
|
+
), nextNode = sourceCode.getNodeByRangeIndex(t.range[1] + 1);
|
82
75
|
context.report({
|
83
76
|
messageId: RULE_ID,
|
84
77
|
data: {
|
@@ -94,16 +87,14 @@ const rule = {
|
|
94
87
|
desc: `Replace with \`${descriptionSyntax}\` description syntax`,
|
95
88
|
fix: (fixer) => fixer.replaceTextRange(
|
96
89
|
[token.start, token.end],
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- TODO: remove `!` when drop support of graphql@15
|
98
90
|
[descriptionSyntax, value.trim(), descriptionSyntax].join("")
|
99
91
|
)
|
100
92
|
}))
|
101
93
|
});
|
102
94
|
}
|
103
95
|
}
|
104
|
-
if (!next)
|
96
|
+
if (!next)
|
105
97
|
break;
|
106
|
-
}
|
107
98
|
token = next;
|
108
99
|
}
|
109
100
|
}
|
@@ -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 rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,9 +1,8 @@
|
|
1
|
-
import "../chunk-
|
2
|
-
import { relative } from "path";
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
|
+
import { relative } from "node:path";
|
3
3
|
import { visit } from "graphql";
|
4
4
|
import { CWD, requireSiblingsOperations } from "../utils.js";
|
5
|
-
const RULE_ID = "no-one-place-fragments"
|
6
|
-
const rule = {
|
5
|
+
const RULE_ID = "no-one-place-fragments", rule = {
|
7
6
|
meta: {
|
8
7
|
type: "suggestion",
|
9
8
|
docs: {
|
@@ -49,7 +48,7 @@ const rule = {
|
|
49
48
|
)
|
50
49
|
}
|
51
50
|
],
|
52
|
-
requiresSiblings:
|
51
|
+
requiresSiblings: !0
|
53
52
|
},
|
54
53
|
messages: {
|
55
54
|
[RULE_ID]: 'Fragment `{{fragmentName}}` used only once. Inline him in "{{filePath}}".'
|
@@ -57,30 +56,24 @@ const rule = {
|
|
57
56
|
schema: []
|
58
57
|
},
|
59
58
|
create(context) {
|
60
|
-
const operations = requireSiblingsOperations(RULE_ID, context);
|
61
|
-
const allDocuments = [...operations.getOperations(), ...operations.getFragments()];
|
62
|
-
const usedFragmentsMap = /* @__PURE__ */ Object.create(null);
|
59
|
+
const operations = requireSiblingsOperations(RULE_ID, context), allDocuments = [...operations.getOperations(), ...operations.getFragments()], usedFragmentsMap = /* @__PURE__ */ Object.create(null);
|
63
60
|
for (const { document, filePath } of allDocuments) {
|
64
61
|
const relativeFilePath = relative(CWD, filePath);
|
65
62
|
visit(document, {
|
66
63
|
FragmentSpread({ name }) {
|
67
64
|
const spreadName = name.value;
|
68
|
-
usedFragmentsMap[spreadName]
|
69
|
-
usedFragmentsMap[spreadName].push(relativeFilePath);
|
65
|
+
usedFragmentsMap[spreadName] ||= [], usedFragmentsMap[spreadName].push(relativeFilePath);
|
70
66
|
}
|
71
67
|
});
|
72
68
|
}
|
73
69
|
return {
|
74
70
|
"FragmentDefinition > Name"(node) {
|
75
|
-
const fragmentName = node.value;
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
data: { fragmentName, filePath: fragmentUsage[0] }
|
82
|
-
});
|
83
|
-
}
|
71
|
+
const fragmentName = node.value, fragmentUsage = usedFragmentsMap[fragmentName];
|
72
|
+
fragmentUsage.length === 1 && context.report({
|
73
|
+
node,
|
74
|
+
messageId: RULE_ID,
|
75
|
+
data: { fragmentName, filePath: fragmentUsage[0] }
|
76
|
+
});
|
84
77
|
}
|
85
78
|
};
|
86
79
|
}
|
@@ -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";
|