@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.
Files changed (222) hide show
  1. package/README.md +2 -0
  2. package/cjs/cache.js +10 -19
  3. package/cjs/configs/index.d.ts +42 -16
  4. package/cjs/configs/index.js +10 -19
  5. package/cjs/configs/operations-all.d.ts +4 -3
  6. package/cjs/configs/operations-all.js +5 -4
  7. package/cjs/configs/operations-recommended.d.ts +3 -1
  8. package/cjs/configs/operations-recommended.js +3 -1
  9. package/cjs/configs/schema-all.d.ts +6 -1
  10. package/cjs/configs/schema-all.js +5 -2
  11. package/cjs/configs/schema-recommended.d.ts +19 -1
  12. package/cjs/configs/schema-recommended.js +22 -2
  13. package/cjs/documents.js +17 -32
  14. package/cjs/estree-converter/converter.js +14 -27
  15. package/cjs/estree-converter/index.js +4 -7
  16. package/cjs/estree-converter/types.js +3 -5
  17. package/cjs/estree-converter/utils.d.ts +2 -3
  18. package/cjs/estree-converter/utils.js +15 -45
  19. package/cjs/flat-configs.d.ts +59 -12
  20. package/cjs/flat-configs.js +9 -14
  21. package/cjs/graphql-config.d.ts +4 -3
  22. package/cjs/graphql-config.js +23 -44
  23. package/cjs/index.d.ts +10 -4
  24. package/cjs/index.js +8 -16
  25. package/cjs/parser.d.ts +4 -3
  26. package/cjs/parser.js +38 -45
  27. package/cjs/processor.d.ts +5 -1
  28. package/cjs/processor.js +25 -57
  29. package/cjs/rules/alphabetize.d.ts +6 -16
  30. package/cjs/rules/alphabetize.js +60 -132
  31. package/cjs/rules/description-style.d.ts +4 -3
  32. package/cjs/rules/description-style.js +11 -18
  33. package/cjs/rules/graphql-js-validation.d.ts +4 -3
  34. package/cjs/rules/graphql-js-validation.js +151 -225
  35. package/cjs/rules/index.d.ts +15 -13
  36. package/cjs/rules/index.js +8 -45
  37. package/cjs/rules/input-name.d.ts +4 -3
  38. package/cjs/rules/input-name.js +43 -59
  39. package/cjs/rules/lone-executable-definition.d.ts +6 -5
  40. package/cjs/rules/lone-executable-definition.js +14 -28
  41. package/cjs/rules/match-document-filename.d.ts +4 -3
  42. package/cjs/rules/match-document-filename.js +39 -70
  43. package/cjs/rules/naming-convention.d.ts +4 -3
  44. package/cjs/rules/naming-convention.js +56 -74
  45. package/cjs/rules/no-anonymous-operations.d.ts +4 -3
  46. package/cjs/rules/no-anonymous-operations.js +11 -18
  47. package/cjs/rules/no-deprecated.d.ts +4 -3
  48. package/cjs/rules/no-deprecated.js +15 -29
  49. package/cjs/rules/no-duplicate-fields.d.ts +4 -3
  50. package/cjs/rules/no-duplicate-fields.js +13 -23
  51. package/cjs/rules/no-hashtag-description.d.ts +4 -3
  52. package/cjs/rules/no-hashtag-description.js +16 -29
  53. package/cjs/rules/no-one-place-fragments.d.ts +4 -3
  54. package/cjs/rules/no-one-place-fragments.js +17 -29
  55. package/cjs/rules/no-root-type.d.ts +4 -3
  56. package/cjs/rules/no-root-type.js +15 -25
  57. package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
  58. package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
  59. package/cjs/rules/no-typename-prefix.d.ts +4 -3
  60. package/cjs/rules/no-typename-prefix.js +26 -33
  61. package/cjs/rules/no-unreachable-types.d.ts +4 -3
  62. package/cjs/rules/no-unreachable-types.js +25 -47
  63. package/cjs/rules/no-unused-fields.d.ts +4 -3
  64. package/cjs/rules/no-unused-fields.js +24 -49
  65. package/cjs/rules/relay-arguments.d.ts +4 -3
  66. package/cjs/rules/relay-arguments.js +20 -43
  67. package/cjs/rules/relay-connection-types.d.ts +4 -3
  68. package/cjs/rules/relay-connection-types.js +14 -45
  69. package/cjs/rules/relay-edge-types.d.ts +4 -3
  70. package/cjs/rules/relay-edge-types.js +48 -99
  71. package/cjs/rules/relay-page-info.d.ts +4 -3
  72. package/cjs/rules/relay-page-info.js +21 -44
  73. package/cjs/rules/require-deprecation-date.d.ts +4 -3
  74. package/cjs/rules/require-deprecation-date.js +15 -31
  75. package/cjs/rules/require-deprecation-reason.d.ts +4 -3
  76. package/cjs/rules/require-deprecation-reason.js +12 -20
  77. package/cjs/rules/require-description.d.ts +4 -3
  78. package/cjs/rules/require-description.js +39 -65
  79. package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
  80. package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
  81. package/cjs/rules/require-import-fragment.d.ts +4 -3
  82. package/cjs/rules/require-import-fragment.js +22 -40
  83. package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
  84. package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
  85. package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
  86. package/cjs/rules/require-nullable-result-in-root.js +34 -44
  87. package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
  88. package/cjs/rules/require-selections.js +198 -0
  89. package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
  90. package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
  91. package/cjs/rules/selection-set-depth.d.ts +4 -3
  92. package/cjs/rules/selection-set-depth.js +18 -34
  93. package/cjs/rules/strict-id-in-types.d.ts +4 -3
  94. package/cjs/rules/strict-id-in-types.js +25 -43
  95. package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
  96. package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
  97. package/cjs/rules/unique-fragment-name.d.ts +3 -2
  98. package/cjs/rules/unique-fragment-name.js +24 -36
  99. package/cjs/rules/unique-operation-name.d.ts +4 -3
  100. package/cjs/rules/unique-operation-name.js +10 -12
  101. package/cjs/schema.d.ts +4 -3
  102. package/cjs/schema.js +14 -27
  103. package/cjs/siblings.d.ts +24 -8
  104. package/cjs/siblings.js +42 -82
  105. package/cjs/types.d.ts +74 -7
  106. package/cjs/types.js +3 -5
  107. package/cjs/utils.d.ts +3 -2
  108. package/cjs/utils.js +27 -44
  109. package/esm/cache.js +4 -8
  110. package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
  111. package/esm/configs/index.d.mts +42 -16
  112. package/esm/configs/index.js +4 -4
  113. package/esm/configs/operations-all.d.mts +4 -3
  114. package/esm/configs/operations-all.js +6 -5
  115. package/esm/configs/operations-recommended.d.mts +3 -1
  116. package/esm/configs/operations-recommended.js +4 -2
  117. package/esm/configs/schema-all.d.mts +6 -1
  118. package/esm/configs/schema-all.js +6 -3
  119. package/esm/configs/schema-recommended.d.mts +19 -1
  120. package/esm/configs/schema-recommended.js +23 -3
  121. package/esm/configs/{relay.js → schema-relay.js} +4 -4
  122. package/esm/documents.js +10 -17
  123. package/esm/estree-converter/converter.js +9 -18
  124. package/esm/estree-converter/utils.d.mts +2 -3
  125. package/esm/estree-converter/utils.js +11 -38
  126. package/esm/flat-configs.d.mts +59 -12
  127. package/esm/flat-configs.js +4 -5
  128. package/esm/graphql-config.d.mts +4 -3
  129. package/esm/graphql-config.js +18 -34
  130. package/esm/index.d.mts +10 -4
  131. package/esm/index.js +1 -1
  132. package/esm/parser.d.mts +4 -3
  133. package/esm/parser.js +33 -27
  134. package/esm/processor.d.mts +5 -1
  135. package/esm/processor.js +21 -46
  136. package/esm/rules/alphabetize.d.mts +6 -16
  137. package/esm/rules/alphabetize.js +53 -118
  138. package/esm/rules/description-style.d.mts +4 -3
  139. package/esm/rules/description-style.js +7 -11
  140. package/esm/rules/graphql-js-validation.d.mts +4 -3
  141. package/esm/rules/graphql-js-validation.js +178 -218
  142. package/esm/rules/index.d.mts +15 -13
  143. package/esm/rules/index.js +5 -5
  144. package/esm/rules/input-name.d.mts +4 -3
  145. package/esm/rules/input-name.js +39 -52
  146. package/esm/rules/lone-executable-definition.d.mts +6 -5
  147. package/esm/rules/lone-executable-definition.js +10 -20
  148. package/esm/rules/match-document-filename.d.mts +4 -3
  149. package/esm/rules/match-document-filename.js +35 -61
  150. package/esm/rules/naming-convention.d.mts +4 -3
  151. package/esm/rules/naming-convention.js +51 -65
  152. package/esm/rules/no-anonymous-operations.d.mts +4 -3
  153. package/esm/rules/no-anonymous-operations.js +6 -9
  154. package/esm/rules/no-deprecated.d.mts +4 -3
  155. package/esm/rules/no-deprecated.js +10 -20
  156. package/esm/rules/no-duplicate-fields.d.mts +4 -3
  157. package/esm/rules/no-duplicate-fields.js +9 -16
  158. package/esm/rules/no-hashtag-description.d.mts +4 -3
  159. package/esm/rules/no-hashtag-description.js +11 -20
  160. package/esm/rules/no-one-place-fragments.d.mts +4 -3
  161. package/esm/rules/no-one-place-fragments.js +12 -19
  162. package/esm/rules/no-root-type.d.mts +4 -3
  163. package/esm/rules/no-root-type.js +11 -18
  164. package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
  165. package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
  166. package/esm/rules/no-typename-prefix.d.mts +4 -3
  167. package/esm/rules/no-typename-prefix.js +22 -26
  168. package/esm/rules/no-unreachable-types.d.mts +4 -3
  169. package/esm/rules/no-unreachable-types.js +18 -33
  170. package/esm/rules/no-unused-fields.d.mts +4 -3
  171. package/esm/rules/no-unused-fields.js +19 -40
  172. package/esm/rules/relay-arguments.d.mts +4 -3
  173. package/esm/rules/relay-arguments.js +15 -34
  174. package/esm/rules/relay-connection-types.d.mts +4 -3
  175. package/esm/rules/relay-connection-types.js +10 -38
  176. package/esm/rules/relay-edge-types.d.mts +4 -3
  177. package/esm/rules/relay-edge-types.js +43 -89
  178. package/esm/rules/relay-page-info.d.mts +4 -3
  179. package/esm/rules/relay-page-info.js +16 -34
  180. package/esm/rules/require-deprecation-date.d.mts +4 -3
  181. package/esm/rules/require-deprecation-date.js +10 -22
  182. package/esm/rules/require-deprecation-reason.d.mts +4 -3
  183. package/esm/rules/require-deprecation-reason.js +7 -11
  184. package/esm/rules/require-description.d.mts +4 -3
  185. package/esm/rules/require-description.js +34 -55
  186. package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
  187. package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
  188. package/esm/rules/require-import-fragment.d.mts +4 -3
  189. package/esm/rules/require-import-fragment.js +14 -26
  190. package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
  191. package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
  192. package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
  193. package/esm/rules/require-nullable-result-in-root.js +29 -35
  194. package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
  195. package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
  196. package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
  197. package/esm/rules/require-type-pattern-with-oneof.js +11 -16
  198. package/esm/rules/selection-set-depth.d.mts +4 -3
  199. package/esm/rules/selection-set-depth.js +11 -20
  200. package/esm/rules/strict-id-in-types.d.mts +4 -3
  201. package/esm/rules/strict-id-in-types.js +20 -34
  202. package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
  203. package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
  204. package/esm/rules/unique-fragment-name.d.mts +3 -2
  205. package/esm/rules/unique-fragment-name.js +20 -27
  206. package/esm/rules/unique-operation-name.d.mts +4 -3
  207. package/esm/rules/unique-operation-name.js +6 -5
  208. package/esm/schema.d.mts +4 -3
  209. package/esm/schema.js +7 -12
  210. package/esm/siblings.d.mts +24 -8
  211. package/esm/siblings.js +37 -73
  212. package/esm/types.d.mts +74 -7
  213. package/esm/utils.d.mts +3 -2
  214. package/esm/utils.js +20 -31
  215. package/index.browser.mjs +5323 -0
  216. package/package.json +8 -13
  217. package/cjs/rules/require-id-when-available.js +0 -241
  218. package/cjs/types-8d5f4ae0.d.ts +0 -107
  219. package/esm/types-ace77d86.d.ts +0 -107
  220. /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
  221. /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
  222. /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
package/esm/processor.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./chunk-BMTV3EA2.js";
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
- let onDiskConfigLoaded = false;
12
- const RELEVANT_KEYWORDS = ["gql", "graphql", "GraphQL"];
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
- if (!onDiskConfigLoaded) {
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 == null ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions.pluckConfig;
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 sources = gqlPluckFromCodeStringSync(filePath, code, {
43
- skipIndent: true,
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
- if (error instanceof Error) {
61
- error.message = `[graphql-eslint] Error while preprocessing "${relative(
62
- CWD,
63
- filePath
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
- const isVueOrSvelte = /\.(vue|svelte)$/.test(filePath);
78
- if (isVueOrSvelte) {
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
- const result = messages.flat();
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 { f as GraphQLESLintRule } from '../types-ace77d86.js';
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 'graphql-config';
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 items: {
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 items: {
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;
@@ -1,34 +1,28 @@
1
- import "../chunk-BMTV3EA2.js";
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: false,
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
- ...ARRAY_DEFAULT_OPTIONS,
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
- ...ARRAY_DEFAULT_OPTIONS,
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: [Kind.ENUM_TYPE_DEFINITION] }],
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: [Kind.ENUM_TYPE_DEFINITION] }],
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: valuesEnum,
189
- arguments: argumentsEnum
190
- // TODO: add in graphql-eslint v4
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: variablesEnum,
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
- if (node.kind === Kind.VARIABLE) {
237
- node = node.parent;
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
- const currName = "alias" in currNode && ((_a2 = currNode.alias) == null ? void 0 : _a2.value) || "name" in currNode && ((_b2 = currNode.name) == null ? void 0 : _b2.value);
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
- const { groups } = opts;
258
- let shouldSortByGroup = false;
259
- if (groups == null ? void 0 : groups.length) {
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
- if (indexForPrev === -1)
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
- const fieldsSelector = kinds.join(",");
323
- const hasEnumValues = ((_b = opts.values) == null ? void 0 : _b[0]) === Kind.ENUM_TYPE_DEFINITION;
324
- const selectionsSelector = (_c = opts.selections) == null ? void 0 : _c.join(",");
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
- if (selectionsSelector) {
339
- listeners[`:matches(${selectionsSelector}) SelectionSet`] = (node) => {
340
- checkNodes(node.selections);
341
- };
342
- }
343
- if (hasVariables) {
344
- listeners.OperationDefinition = (node) => {
345
- var _a2;
346
- checkNodes((_a2 = node.variableDefinitions) == null ? void 0 : _a2.map((varDef) => varDef.variable));
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 { f as GraphQLESLintRule } from '../types-ace77d86.js';
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 'graphql-config';
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-BMTV3EA2.js";
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: false,
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: true,
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: true
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 sourceCode = context.getSourceCode();
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 { f as GraphQLESLintRule } from '../types-ace77d86.js';
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