@graphql-eslint/eslint-plugin 4.0.0-alpha.1 → 4.0.0-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. package/{esm/cache.d.mts → cjs/cache.d.cts} +1 -1
  2. package/cjs/cache.js +1 -1
  3. package/cjs/configs/index.d.cts +9 -0
  4. package/cjs/configs/index.js +1 -1
  5. package/cjs/documents.js +1 -1
  6. package/{esm/estree-converter/converter.d.mts → cjs/estree-converter/converter.d.cts} +1 -1
  7. package/cjs/estree-converter/index.d.cts +8 -0
  8. package/{esm/estree-converter/utils.d.mts → cjs/estree-converter/utils.d.cts} +3 -3
  9. package/cjs/flat-configs.d.cts +75 -0
  10. package/cjs/flat-configs.js +1 -3
  11. package/{esm/graphql-config.d.mts → cjs/graphql-config.d.cts} +3 -3
  12. package/cjs/graphql-config.js +2 -2
  13. package/{esm/index.d.mts → cjs/index.d.cts} +14 -10
  14. package/cjs/index.js +2 -0
  15. package/cjs/meta.d.cts +4 -0
  16. package/cjs/meta.js +36 -0
  17. package/cjs/package.json +1 -0
  18. package/{esm/parser.d.mts → cjs/parser.d.cts} +11 -4
  19. package/cjs/parser.js +12 -3
  20. package/{esm/processor.d.mts → cjs/processor.d.cts} +4 -0
  21. package/cjs/processor.js +5 -1
  22. package/{esm/rules/alphabetize.d.mts → cjs/rules/alphabetize.d.cts} +3 -3
  23. package/cjs/rules/alphabetize.js +1 -1
  24. package/{esm/rules/description-style.d.mts → cjs/rules/description-style.d.cts} +3 -3
  25. package/{esm/rules/graphql-js-validation.d.mts → cjs/rules/graphql-js-validation.d.cts} +3 -3
  26. package/{esm/rules/index.d.mts → cjs/rules/index.d.cts} +5 -5
  27. package/{esm/rules/input-name.d.mts → cjs/rules/input-name.d.cts} +3 -3
  28. package/{esm/rules/lone-executable-definition.d.mts → cjs/rules/lone-executable-definition.d.cts} +3 -3
  29. package/{esm/rules/match-document-filename.d.mts → cjs/rules/match-document-filename.d.cts} +4 -4
  30. package/cjs/rules/match-document-filename.js +2 -2
  31. package/{esm/rules/naming-convention.d.mts → cjs/rules/naming-convention.d.cts} +3 -3
  32. package/cjs/rules/no-anonymous-operations.d.cts +13 -0
  33. package/{esm/rules/no-deprecated.d.mts → cjs/rules/no-deprecated.d.cts} +3 -3
  34. package/cjs/rules/no-duplicate-fields.d.cts +13 -0
  35. package/{esm/rules/no-hashtag-description.d.mts → cjs/rules/no-hashtag-description.d.cts} +3 -3
  36. package/cjs/rules/no-one-place-fragments.d.cts +13 -0
  37. package/{esm/rules/no-root-type.d.mts → cjs/rules/no-root-type.d.cts} +3 -3
  38. package/cjs/rules/no-scalar-result-type-on-mutation.d.cts +13 -0
  39. package/cjs/rules/no-typename-prefix.d.cts +13 -0
  40. package/cjs/rules/no-unreachable-types.d.cts +13 -0
  41. package/cjs/rules/no-unreachable-types.js +6 -7
  42. package/cjs/rules/no-unused-fields.d.cts +13 -0
  43. package/cjs/rules/no-unused-fields.js +6 -6
  44. package/{esm/rules/relay-arguments.d.mts → cjs/rules/relay-arguments.d.cts} +3 -3
  45. package/{esm/rules/relay-connection-types.d.mts → cjs/rules/relay-connection-types.d.cts} +3 -3
  46. package/{esm/rules/relay-edge-types.d.mts → cjs/rules/relay-edge-types.d.cts} +3 -3
  47. package/cjs/rules/relay-edge-types.js +1 -1
  48. package/cjs/rules/relay-page-info.d.cts +13 -0
  49. package/cjs/rules/relay-page-info.js +1 -1
  50. package/{esm/rules/require-deprecation-date.d.mts → cjs/rules/require-deprecation-date.d.cts} +3 -3
  51. package/cjs/rules/require-deprecation-reason.d.cts +13 -0
  52. package/{esm/rules/require-description.d.mts → cjs/rules/require-description.d.cts} +3 -3
  53. package/cjs/rules/require-field-of-type-query-in-mutation-result.d.cts +13 -0
  54. package/cjs/rules/require-import-fragment.d.cts +13 -0
  55. package/cjs/rules/require-import-fragment.js +1 -1
  56. package/cjs/rules/require-nullable-fields-with-oneof.d.cts +13 -0
  57. package/cjs/rules/require-nullable-result-in-root.d.cts +13 -0
  58. package/{esm/rules/require-selections.d.mts → cjs/rules/require-selections.d.cts} +3 -3
  59. package/cjs/rules/require-selections.js +1 -0
  60. package/cjs/rules/require-type-pattern-with-oneof.d.cts +13 -0
  61. package/{esm/rules/selection-set-depth.d.mts → cjs/rules/selection-set-depth.d.cts} +3 -3
  62. package/cjs/rules/selection-set-depth.js +2 -2
  63. package/{esm/rules/strict-id-in-types.d.mts → cjs/rules/strict-id-in-types.d.cts} +3 -3
  64. package/cjs/rules/unique-enum-value-names.d.cts +13 -0
  65. package/{esm/rules/unique-fragment-name.d.mts → cjs/rules/unique-fragment-name.d.cts} +3 -3
  66. package/cjs/rules/unique-operation-name.d.cts +13 -0
  67. package/{esm/schema.d.mts → cjs/schema.d.cts} +3 -3
  68. package/cjs/schema.js +1 -1
  69. package/{esm/types.d.mts → cjs/types.d.cts} +2 -2
  70. package/{esm/utils.d.mts → cjs/utils.d.cts} +3 -3
  71. package/cjs/utils.js +1 -1
  72. package/{cjs → esm}/cache.d.ts +1 -1
  73. package/esm/configs/index.d.ts +9 -0
  74. package/{cjs → esm}/estree-converter/index.d.ts +2 -2
  75. package/{cjs → esm}/estree-converter/utils.d.ts +3 -3
  76. package/esm/flat-configs.d.ts +75 -0
  77. package/esm/flat-configs.js +2 -4
  78. package/esm/graphql-config.js +1 -1
  79. package/{cjs → esm}/index.d.ts +5 -1
  80. package/esm/index.js +2 -1
  81. package/esm/meta.d.ts +4 -0
  82. package/esm/meta.js +7 -0
  83. package/{cjs → esm}/parser.d.ts +8 -1
  84. package/esm/parser.js +10 -1
  85. package/{cjs → esm}/processor.d.ts +4 -0
  86. package/esm/processor.js +5 -0
  87. package/{cjs → esm}/rules/alphabetize.d.ts +1 -1
  88. package/{cjs → esm}/rules/index.d.ts +5 -5
  89. package/esm/rules/match-document-filename.js +2 -2
  90. package/esm/rules/no-unreachable-types.js +6 -6
  91. package/esm/rules/no-unused-fields.js +6 -5
  92. package/esm/rules/relay-edge-types.js +1 -1
  93. package/esm/rules/relay-page-info.js +1 -1
  94. package/esm/rules/require-selections.js +1 -0
  95. package/esm/rules/selection-set-depth.js +1 -1
  96. package/{index.browser.mjs → index.browser.js} +158 -53
  97. package/package.json +5 -4
  98. package/cjs/configs/index.d.ts +0 -174
  99. package/cjs/flat-configs.d.ts +0 -307
  100. package/esm/configs/index.d.mts +0 -174
  101. package/esm/estree-converter/index.d.mts +0 -8
  102. package/esm/flat-configs.d.mts +0 -307
  103. package/esm/package.json +0 -1
  104. package/esm/rules/no-anonymous-operations.d.mts +0 -13
  105. package/esm/rules/no-duplicate-fields.d.mts +0 -13
  106. package/esm/rules/no-one-place-fragments.d.mts +0 -13
  107. package/esm/rules/no-scalar-result-type-on-mutation.d.mts +0 -13
  108. package/esm/rules/no-typename-prefix.d.mts +0 -13
  109. package/esm/rules/no-unreachable-types.d.mts +0 -13
  110. package/esm/rules/no-unused-fields.d.mts +0 -13
  111. package/esm/rules/relay-page-info.d.mts +0 -13
  112. package/esm/rules/require-deprecation-reason.d.mts +0 -13
  113. package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +0 -13
  114. package/esm/rules/require-import-fragment.d.mts +0 -13
  115. package/esm/rules/require-nullable-fields-with-oneof.d.mts +0 -13
  116. package/esm/rules/require-nullable-result-in-root.d.mts +0 -13
  117. package/esm/rules/require-type-pattern-with-oneof.d.mts +0 -13
  118. package/esm/rules/unique-enum-value-names.d.mts +0 -13
  119. package/esm/rules/unique-operation-name.d.mts +0 -13
  120. /package/cjs/configs/{operations-all.d.ts → operations-all.d.cts} +0 -0
  121. /package/cjs/configs/{operations-recommended.d.ts → operations-recommended.d.cts} +0 -0
  122. /package/cjs/configs/{schema-all.d.ts → schema-all.d.cts} +0 -0
  123. /package/cjs/configs/{schema-recommended.d.ts → schema-recommended.d.cts} +0 -0
  124. /package/cjs/configs/{schema-relay.d.ts → schema-relay.d.cts} +0 -0
  125. /package/cjs/{documents.d.ts → documents.d.cts} +0 -0
  126. /package/cjs/estree-converter/{types.d.ts → types.d.cts} +0 -0
  127. /package/cjs/{siblings.d.ts → siblings.d.cts} +0 -0
  128. /package/esm/configs/{operations-all.d.mts → operations-all.d.ts} +0 -0
  129. /package/esm/configs/{operations-recommended.d.mts → operations-recommended.d.ts} +0 -0
  130. /package/esm/configs/{schema-all.d.mts → schema-all.d.ts} +0 -0
  131. /package/esm/configs/{schema-recommended.d.mts → schema-recommended.d.ts} +0 -0
  132. /package/esm/configs/{schema-relay.d.mts → schema-relay.d.ts} +0 -0
  133. /package/esm/{documents.d.mts → documents.d.ts} +0 -0
  134. /package/{cjs → esm}/estree-converter/converter.d.ts +0 -0
  135. /package/esm/estree-converter/{types.d.mts → types.d.ts} +0 -0
  136. /package/{cjs → esm}/graphql-config.d.ts +0 -0
  137. /package/{cjs → esm}/rules/description-style.d.ts +0 -0
  138. /package/{cjs → esm}/rules/graphql-js-validation.d.ts +0 -0
  139. /package/{cjs → esm}/rules/input-name.d.ts +0 -0
  140. /package/{cjs → esm}/rules/lone-executable-definition.d.ts +0 -0
  141. /package/{cjs → esm}/rules/match-document-filename.d.ts +0 -0
  142. /package/{cjs → esm}/rules/naming-convention.d.ts +0 -0
  143. /package/{cjs → esm}/rules/no-anonymous-operations.d.ts +0 -0
  144. /package/{cjs → esm}/rules/no-deprecated.d.ts +0 -0
  145. /package/{cjs → esm}/rules/no-duplicate-fields.d.ts +0 -0
  146. /package/{cjs → esm}/rules/no-hashtag-description.d.ts +0 -0
  147. /package/{cjs → esm}/rules/no-one-place-fragments.d.ts +0 -0
  148. /package/{cjs → esm}/rules/no-root-type.d.ts +0 -0
  149. /package/{cjs → esm}/rules/no-scalar-result-type-on-mutation.d.ts +0 -0
  150. /package/{cjs → esm}/rules/no-typename-prefix.d.ts +0 -0
  151. /package/{cjs → esm}/rules/no-unreachable-types.d.ts +0 -0
  152. /package/{cjs → esm}/rules/no-unused-fields.d.ts +0 -0
  153. /package/{cjs → esm}/rules/relay-arguments.d.ts +0 -0
  154. /package/{cjs → esm}/rules/relay-connection-types.d.ts +0 -0
  155. /package/{cjs → esm}/rules/relay-edge-types.d.ts +0 -0
  156. /package/{cjs → esm}/rules/relay-page-info.d.ts +0 -0
  157. /package/{cjs → esm}/rules/require-deprecation-date.d.ts +0 -0
  158. /package/{cjs → esm}/rules/require-deprecation-reason.d.ts +0 -0
  159. /package/{cjs → esm}/rules/require-description.d.ts +0 -0
  160. /package/{cjs → esm}/rules/require-field-of-type-query-in-mutation-result.d.ts +0 -0
  161. /package/{cjs → esm}/rules/require-import-fragment.d.ts +0 -0
  162. /package/{cjs → esm}/rules/require-nullable-fields-with-oneof.d.ts +0 -0
  163. /package/{cjs → esm}/rules/require-nullable-result-in-root.d.ts +0 -0
  164. /package/{cjs → esm}/rules/require-selections.d.ts +0 -0
  165. /package/{cjs → esm}/rules/require-type-pattern-with-oneof.d.ts +0 -0
  166. /package/{cjs → esm}/rules/selection-set-depth.d.ts +0 -0
  167. /package/{cjs → esm}/rules/strict-id-in-types.d.ts +0 -0
  168. /package/{cjs → esm}/rules/unique-enum-value-names.d.ts +0 -0
  169. /package/{cjs → esm}/rules/unique-fragment-name.d.ts +0 -0
  170. /package/{cjs → esm}/rules/unique-operation-name.d.ts +0 -0
  171. /package/{cjs → esm}/schema.d.ts +0 -0
  172. /package/esm/{siblings.d.mts → siblings.d.ts} +0 -0
  173. /package/{cjs → esm}/types.d.ts +0 -0
  174. /package/{cjs → esm}/utils.d.ts +0 -0
@@ -237,10 +237,32 @@ var require_schema_relay = __commonJS({
237
237
  });
238
238
 
239
239
  // src/parser.ts
240
- import debugFactory from "debug";
240
+ import debugFactory2 from "debug";
241
241
  import { buildSchema, GraphQLError } from "graphql";
242
242
  import { parseGraphQLSDL } from "@graphql-tools/utils";
243
243
 
244
+ // src/cache.ts
245
+ import debugFactory from "debug";
246
+ var log = debugFactory("graphql-eslint:ModuleCache"), ModuleCache = class {
247
+ map = /* @__PURE__ */ new Map();
248
+ set(cacheKey, result) {
249
+ this.map.set(cacheKey, { lastSeen: process.hrtime(), result }), log("setting entry for", cacheKey);
250
+ }
251
+ get(cacheKey, settings = {
252
+ lifetime: 10
253
+ /* seconds */
254
+ }) {
255
+ let value = this.map.get(cacheKey);
256
+ if (!value) {
257
+ log("cache miss for", cacheKey);
258
+ return;
259
+ }
260
+ let { lastSeen, result } = value;
261
+ if (process.env.NODE || process.hrtime(lastSeen)[0] < settings.lifetime)
262
+ return result;
263
+ }
264
+ };
265
+
244
266
  // src/estree-converter/converter.ts
245
267
  import {
246
268
  Kind,
@@ -374,6 +396,84 @@ function convertToESTree(node, schema15) {
374
396
  );
375
397
  }
376
398
 
399
+ // package.json
400
+ var package_default = {
401
+ name: "@graphql-eslint/eslint-plugin",
402
+ version: "4.0.0-alpha.2",
403
+ type: "module",
404
+ description: "GraphQL plugin for ESLint",
405
+ repository: "https://github.com/B2o5T/graphql-eslint",
406
+ author: "Dotan Simha <dotansimha@gmail.com>",
407
+ license: "MIT",
408
+ engines: {
409
+ node: ">=18"
410
+ },
411
+ main: "dist/cjs/index.js",
412
+ exports: {
413
+ "./package.json": "./package.json",
414
+ ".": {
415
+ require: {
416
+ types: "./dist/cjs/index.d.ts",
417
+ default: "./dist/cjs/index.js"
418
+ },
419
+ import: {
420
+ types: "./dist/esm/index.d.ts",
421
+ default: "./dist/esm/index.js"
422
+ },
423
+ default: {
424
+ types: "./dist/esm/index.d.ts",
425
+ default: "./dist/esm/index.js"
426
+ }
427
+ }
428
+ },
429
+ types: "dist/esm/index.d.ts",
430
+ keywords: [
431
+ "eslint",
432
+ "eslintplugin",
433
+ "eslint-plugin",
434
+ "graphql"
435
+ ],
436
+ scripts: {
437
+ build: "tsup",
438
+ test: "vitest",
439
+ typecheck: "tsc --noEmit"
440
+ },
441
+ peerDependencies: {
442
+ eslint: ">=8.44.0",
443
+ graphql: "^16"
444
+ },
445
+ dependencies: {
446
+ "@graphql-tools/code-file-loader": "^8.0.0",
447
+ "@graphql-tools/graphql-tag-pluck": "^8.0.0",
448
+ "@graphql-tools/utils": "^10.0.0",
449
+ debug: "^4.3.4",
450
+ "fast-glob": "^3.2.12",
451
+ "graphql-config": "^5.0.0",
452
+ "graphql-depth-limit": "^1.1.0",
453
+ "lodash.lowercase": "^4.3.0"
454
+ },
455
+ devDependencies: {
456
+ "@theguild/eslint-rule-tester": "workspace:*",
457
+ "@types/debug": "4.1.12",
458
+ "@types/eslint": "9.6.0",
459
+ "@types/estree": "1.0.5",
460
+ "@types/graphql-depth-limit": "1.1.6",
461
+ "@types/json-schema": "7.0.15",
462
+ "@types/lodash.lowercase": "4.3.9",
463
+ graphql: "16.9.0",
464
+ "json-schema-to-ts": "2.12.0",
465
+ "vite-tsconfig-paths": "^4.3.2"
466
+ },
467
+ publishConfig: {
468
+ directory: "dist",
469
+ access: "public"
470
+ },
471
+ sideEffects: !1
472
+ };
473
+
474
+ // src/meta.ts
475
+ var { name, version } = package_default;
476
+
377
477
  // src/siblings.ts
378
478
  import {
379
479
  Kind as Kind3,
@@ -550,7 +650,7 @@ function getSiblings(documents) {
550
650
  cachedOperations = result;
551
651
  }
552
652
  return cachedOperations;
553
- }, getFragment = (name) => getFragments().filter((f) => f.document.name.value === name), collectFragments = (selectable, recursive, collected = /* @__PURE__ */ new Map()) => (visit2(selectable, {
653
+ }, getFragment = (name2) => getFragments().filter((f) => f.document.name.value === name2), collectFragments = (selectable, recursive, collected = /* @__PURE__ */ new Map()) => (visit2(selectable, {
554
654
  FragmentSpread(spread) {
555
655
  let fragmentName = spread.name.value, [fragment] = getFragment(fragmentName);
556
656
  if (!fragment) {
@@ -567,7 +667,7 @@ function getSiblings(documents) {
567
667
  getFragments,
568
668
  getFragmentByType: (typeName) => getFragments().filter((f) => f.document.typeCondition.name.value === typeName),
569
669
  getFragmentsInUse: (selectable, recursive = !0) => Array.from(collectFragments(selectable, recursive).values()),
570
- getOperation: (name) => getOperations().filter((o) => o.document.name?.value === name),
670
+ getOperation: (name2) => getOperations().filter((o) => o.document.name?.value === name2),
571
671
  getOperations,
572
672
  getOperationByType: (type) => getOperations().filter((o) => o.document.operation === type)
573
673
  };
@@ -575,7 +675,7 @@ function getSiblings(documents) {
575
675
  }
576
676
 
577
677
  // src/parser.ts
578
- var debug = debugFactory("graphql-eslint:parser");
678
+ var debug = debugFactory2("graphql-eslint:parser");
579
679
  debug("cwd %o", CWD);
580
680
  var LEGACY_PARSER_OPTIONS_KEYS = [
581
681
  "schema",
@@ -640,6 +740,13 @@ function parseForESLint(code, options) {
640
740
  throw error;
641
741
  }
642
742
  }
743
+ var parser = {
744
+ parseForESLint,
745
+ meta: {
746
+ name: "@graphql-eslint/parser",
747
+ version
748
+ }
749
+ };
643
750
 
644
751
  // src/rules/alphabetize.ts
645
752
  import {
@@ -1078,10 +1185,10 @@ function validateDocument({
1078
1185
  loc,
1079
1186
  message: error.message,
1080
1187
  suggest: hasDidYouMeanSuggestions ? matches.map((match) => {
1081
- let { name } = match.groups;
1188
+ let { name: name2 } = match.groups;
1082
1189
  return {
1083
- desc: `Rename to \`${name}\``,
1084
- fix: (fixer) => fixer.replaceText(token, name)
1190
+ desc: `Rename to \`${name2}\``,
1191
+ fix: (fixer) => fixer.replaceText(token, name2)
1085
1192
  };
1086
1193
  }) : []
1087
1194
  });
@@ -1105,7 +1212,7 @@ var getFragmentDefsAndFragmentSpreads = (node) => {
1105
1212
  }), { fragmentDefs, fragmentSpreads };
1106
1213
  }, getMissingFragments = (node) => {
1107
1214
  let { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
1108
- return [...fragmentSpreads].filter((name) => !fragmentDefs.has(name));
1215
+ return [...fragmentSpreads].filter((name2) => !fragmentDefs.has(name2));
1109
1216
  }, handleMissingFragments = ({ ruleId, context, node }) => {
1110
1217
  let missingFragments = getMissingFragments(node);
1111
1218
  if (missingFragments.length > 0) {
@@ -1742,10 +1849,10 @@ Using the same name for all input parameters will make your schemas easier to co
1742
1849
  return currentNode;
1743
1850
  })(node);
1744
1851
  if (shouldCheckType(inputValueNode.parent.parent)) {
1745
- let mutationName = `${inputValueNode.parent.name.value}Input`, name = node.name.value;
1746
- (options.caseSensitiveInputType && node.name.value !== mutationName || name.toLowerCase() !== mutationName.toLowerCase()) && context.report({
1852
+ let mutationName = `${inputValueNode.parent.name.value}Input`, name2 = node.name.value;
1853
+ (options.caseSensitiveInputType && node.name.value !== mutationName || name2.toLowerCase() !== mutationName.toLowerCase()) && context.report({
1747
1854
  node: node.name,
1748
- message: `Input type \`${name}\` name should be \`${mutationName}\`.`,
1855
+ message: `Input type \`${name2}\` name should be \`${mutationName}\`.`,
1749
1856
  suggest: [
1750
1857
  {
1751
1858
  desc: `Rename to \`${mutationName}\``,
@@ -1828,11 +1935,11 @@ var RULE_ID2 = "lone-executable-definition", definitionTypes = ["fragment", ...O
1828
1935
  },
1829
1936
  "Document:exit"() {
1830
1937
  for (let { node, type } of definitions.slice(1)) {
1831
- let name = pascalCase(type), definitionName = node.name?.value;
1832
- definitionName && (name += ` "${definitionName}"`), context.report({
1938
+ let name2 = pascalCase(type), definitionName = node.name?.value;
1939
+ definitionName && (name2 += ` "${definitionName}"`), context.report({
1833
1940
  loc: node.name?.loc || getLocation(node.loc.start, type),
1834
1941
  messageId: RULE_ID2,
1835
- data: { name }
1942
+ data: { name: name2 }
1836
1943
  });
1837
1944
  }
1838
1945
  }
@@ -2399,51 +2506,51 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
2399
2506
  report(node, `${nodeType} "${nodeName}" should ${errorMessage}`, suggestedNames);
2400
2507
  }
2401
2508
  function getError() {
2402
- let name = nodeName.replace(/(^_+)|(_+$)/g, "");
2403
- if (ignorePattern && new RegExp(ignorePattern, "u").test(name))
2509
+ let name2 = nodeName.replace(/(^_+)|(_+$)/g, "");
2510
+ if (ignorePattern && new RegExp(ignorePattern, "u").test(name2))
2404
2511
  return;
2405
- if (prefix && !name.startsWith(prefix))
2512
+ if (prefix && !name2.startsWith(prefix))
2406
2513
  return {
2407
2514
  errorMessage: `have "${prefix}" prefix`,
2408
- renameToNames: [prefix + name]
2515
+ renameToNames: [prefix + name2]
2409
2516
  };
2410
- if (suffix && !name.endsWith(suffix))
2517
+ if (suffix && !name2.endsWith(suffix))
2411
2518
  return {
2412
2519
  errorMessage: `have "${suffix}" suffix`,
2413
- renameToNames: [name + suffix]
2520
+ renameToNames: [name2 + suffix]
2414
2521
  };
2415
- let forbiddenPrefix = forbiddenPrefixes?.find((prefix2) => name.startsWith(prefix2));
2522
+ let forbiddenPrefix = forbiddenPrefixes?.find((prefix2) => name2.startsWith(prefix2));
2416
2523
  if (forbiddenPrefix)
2417
2524
  return {
2418
2525
  errorMessage: `not have "${forbiddenPrefix}" prefix`,
2419
- renameToNames: [name.replace(new RegExp(`^${forbiddenPrefix}`), "")]
2526
+ renameToNames: [name2.replace(new RegExp(`^${forbiddenPrefix}`), "")]
2420
2527
  };
2421
- let forbiddenSuffix = forbiddenSuffixes?.find((suffix2) => name.endsWith(suffix2));
2528
+ let forbiddenSuffix = forbiddenSuffixes?.find((suffix2) => name2.endsWith(suffix2));
2422
2529
  if (forbiddenSuffix)
2423
2530
  return {
2424
2531
  errorMessage: `not have "${forbiddenSuffix}" suffix`,
2425
- renameToNames: [name.replace(new RegExp(`${forbiddenSuffix}$`), "")]
2532
+ renameToNames: [name2.replace(new RegExp(`${forbiddenSuffix}$`), "")]
2426
2533
  };
2427
- if (requiredPrefixes && !requiredPrefixes.some((requiredPrefix) => name.startsWith(requiredPrefix)))
2534
+ if (requiredPrefixes && !requiredPrefixes.some((requiredPrefix) => name2.startsWith(requiredPrefix)))
2428
2535
  return {
2429
2536
  errorMessage: `have one of the following prefixes: ${englishJoinWords(
2430
2537
  requiredPrefixes
2431
2538
  )}`,
2432
- renameToNames: style ? requiredPrefixes.map((prefix2) => convertCase(style, `${prefix2} ${name}`)) : requiredPrefixes.map((prefix2) => `${prefix2}${name}`)
2539
+ renameToNames: style ? requiredPrefixes.map((prefix2) => convertCase(style, `${prefix2} ${name2}`)) : requiredPrefixes.map((prefix2) => `${prefix2}${name2}`)
2433
2540
  };
2434
- if (requiredSuffixes && !requiredSuffixes.some((requiredSuffix) => name.endsWith(requiredSuffix)))
2541
+ if (requiredSuffixes && !requiredSuffixes.some((requiredSuffix) => name2.endsWith(requiredSuffix)))
2435
2542
  return {
2436
2543
  errorMessage: `have one of the following suffixes: ${englishJoinWords(
2437
2544
  requiredSuffixes
2438
2545
  )}`,
2439
- renameToNames: style ? requiredSuffixes.map((suffix2) => convertCase(style, `${name} ${suffix2}`)) : requiredSuffixes.map((suffix2) => `${name}${suffix2}`)
2546
+ renameToNames: style ? requiredSuffixes.map((suffix2) => convertCase(style, `${name2} ${suffix2}`)) : requiredSuffixes.map((suffix2) => `${name2}${suffix2}`)
2440
2547
  };
2441
2548
  if (!style)
2442
2549
  return;
2443
- if (!StyleToRegex[style].test(name))
2550
+ if (!StyleToRegex[style].test(name2))
2444
2551
  return {
2445
2552
  errorMessage: `be in ${style} format`,
2446
- renameToNames: [convertCase(style, name)]
2553
+ renameToNames: [convertCase(style, name2)]
2447
2554
  };
2448
2555
  }
2449
2556
  }, checkUnderscore = (isLeading) => (node) => {
@@ -2930,8 +3037,8 @@ var RULE_ID7 = "no-one-place-fragments", rule11 = {
2930
3037
  for (let { document, filePath } of allDocuments) {
2931
3038
  let relativeFilePath = relative(CWD, filePath);
2932
3039
  visit4(document, {
2933
- FragmentSpread({ name }) {
2934
- let spreadName = name.value;
3040
+ FragmentSpread({ name: name2 }) {
3041
+ let spreadName = name2.value;
2935
3042
  usedFragmentsMap[spreadName] ||= [], usedFragmentsMap[spreadName].push(relativeFilePath);
2936
3043
  }
2937
3044
  });
@@ -3186,7 +3293,7 @@ var RULE_ID9 = "no-unreachable-types", KINDS = [
3186
3293
  Kind13.UNION_TYPE_EXTENSION,
3187
3294
  Kind13.ENUM_TYPE_DEFINITION,
3188
3295
  Kind13.ENUM_TYPE_EXTENSION
3189
- ], reachableTypesCache, RequestDirectiveLocations = /* @__PURE__ */ new Set([
3296
+ ], reachableTypesCache = new ModuleCache(), RequestDirectiveLocations = /* @__PURE__ */ new Set([
3190
3297
  DirectiveLocation.QUERY,
3191
3298
  DirectiveLocation.MUTATION,
3192
3299
  DirectiveLocation.SUBSCRIPTION,
@@ -3197,8 +3304,9 @@ var RULE_ID9 = "no-unreachable-types", KINDS = [
3197
3304
  DirectiveLocation.VARIABLE_DEFINITION
3198
3305
  ]);
3199
3306
  function getReachableTypes(schema15) {
3200
- if (reachableTypesCache)
3201
- return reachableTypesCache;
3307
+ let cachedValue = reachableTypesCache.get(schema15);
3308
+ if (cachedValue)
3309
+ return cachedValue;
3202
3310
  let reachableTypes = /* @__PURE__ */ new Set(), collect = (node) => {
3203
3311
  let typeName = getTypeName(node);
3204
3312
  if (reachableTypes.has(typeName))
@@ -3235,7 +3343,7 @@ function getReachableTypes(schema15) {
3235
3343
  argTypeName && reachableTypes.add(argTypeName);
3236
3344
  }
3237
3345
  }
3238
- return reachableTypesCache = reachableTypes, reachableTypesCache;
3346
+ return reachableTypesCache.set(schema15, reachableTypes), reachableTypes;
3239
3347
  }
3240
3348
  var rule15 = {
3241
3349
  meta: {
@@ -3316,10 +3424,11 @@ var rule15 = {
3316
3424
 
3317
3425
  // src/rules/no-unused-fields.ts
3318
3426
  import { TypeInfo as TypeInfo2, visit as visit6, visitWithTypeInfo as visitWithTypeInfo2 } from "graphql";
3319
- var RULE_ID10 = "no-unused-fields", usedFieldsCache;
3427
+ var RULE_ID10 = "no-unused-fields", usedFieldsCache = new ModuleCache();
3320
3428
  function getUsedFields(schema15, operations) {
3321
- if (usedFieldsCache)
3322
- return usedFieldsCache;
3429
+ let cachedValue = usedFieldsCache.get(schema15);
3430
+ if (cachedValue)
3431
+ return cachedValue;
3323
3432
  let usedFields = /* @__PURE__ */ Object.create(null), typeInfo = new TypeInfo2(schema15), visitor = visitWithTypeInfo2(typeInfo, {
3324
3433
  Field(node) {
3325
3434
  if (!typeInfo.getFieldDef())
@@ -3330,7 +3439,7 @@ function getUsedFields(schema15, operations) {
3330
3439
  }), allDocuments = [...operations.getOperations(), ...operations.getFragments()];
3331
3440
  for (let { document } of allDocuments)
3332
3441
  visit6(document, visitor);
3333
- return usedFieldsCache = usedFields, usedFieldsCache;
3442
+ return usedFieldsCache.set(schema15, usedFields), usedFields;
3334
3443
  }
3335
3444
  var rule16 = {
3336
3445
  meta: {
@@ -4463,7 +4572,7 @@ var RULE_ID18 = "require-nullable-result-in-root", rule27 = {
4463
4572
  for (let field of node.fields || []) {
4464
4573
  if (field.gqlType.type !== Kind20.NON_NULL_TYPE || field.gqlType.gqlType.type !== Kind20.NAMED_TYPE)
4465
4574
  continue;
4466
- let name = field.gqlType.gqlType.name.value, type = schema15.getType(name), resultType = type?.astNode ? getNodeName(type.astNode) : type?.name;
4575
+ let name2 = field.gqlType.gqlType.name.value, type = schema15.getType(name2), resultType = type?.astNode ? getNodeName(type.astNode) : type?.name;
4467
4576
  context.report({
4468
4577
  node: field.gqlType,
4469
4578
  messageId: RULE_ID18,
@@ -4520,6 +4629,7 @@ var RULE_ID19 = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema12 = {
4520
4629
  }, rule28 = {
4521
4630
  meta: {
4522
4631
  type: "suggestion",
4632
+ // eslint-disable-next-line eslint-plugin/require-meta-has-suggestions -- false positive since we assign `problem.suggest` conditionally
4523
4633
  hasSuggestions: !0,
4524
4634
  docs: {
4525
4635
  category: "Operations",
@@ -4622,7 +4732,7 @@ Include it in your selection set{{ addition }}.`
4622
4732
  }
4623
4733
  function checkFields(rawType2) {
4624
4734
  let fields = rawType2.getFields();
4625
- if (!idNames.some((name) => fields[name]))
4735
+ if (!idNames.some((name2) => fields[name2]))
4626
4736
  return;
4627
4737
  function hasIdField({ selections }) {
4628
4738
  return selections.some((selection) => {
@@ -4644,8 +4754,8 @@ Include it in your selection set{{ addition }}.`
4644
4754
  if (checkFragments(node), hasId)
4645
4755
  return;
4646
4756
  let pluralSuffix = idNames.length > 1 ? "s" : "", fieldName2 = englishJoinWords(
4647
- idNames.map((name) => `\`${(parent.alias || parent.name).value}.${name}\``)
4648
- ), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
4757
+ idNames.map((name2) => `\`${(parent.alias || parent.name).value}.${name2}\``)
4758
+ ), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name2) => `\`${name2}\``))}`, problem = {
4649
4759
  loc,
4650
4760
  messageId: RULE_ID19,
4651
4761
  data: {
@@ -4825,7 +4935,7 @@ var RULE_ID21 = "selection-set-depth", schema13 = {
4825
4935
  checkFn({
4826
4936
  getDocument: () => document,
4827
4937
  reportError(error) {
4828
- let { line, column } = error.locations[0], token = context.getAncestors()[0].tokens.find(
4938
+ let { line, column } = error.locations[0], token = context.sourceCode.getAncestors(node)[0].tokens.find(
4829
4939
  (token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
4830
4940
  );
4831
4941
  context.report({
@@ -5269,7 +5379,7 @@ var rules = {
5269
5379
  };
5270
5380
 
5271
5381
  // src/configs/index.ts
5272
- var import_operations_all = __toESM(require_operations_all()), import_operations_recommended = __toESM(require_operations_recommended()), import_schema_all = __toESM(require_schema_all()), import_schema_recommended = __toESM(require_schema_recommended()), import_schema_relay = __toESM(require_schema_relay()), configs = {
5382
+ var import_operations_all = __toESM(require_operations_all(), 1), import_operations_recommended = __toESM(require_operations_recommended(), 1), import_schema_all = __toESM(require_schema_all(), 1), import_schema_recommended = __toESM(require_schema_recommended(), 1), import_schema_relay = __toESM(require_schema_relay(), 1), configs = {
5273
5383
  "schema-recommended": import_schema_recommended.default,
5274
5384
  "schema-all": import_schema_all.default,
5275
5385
  "schema-relay": import_schema_relay.default,
@@ -5278,9 +5388,7 @@ var import_operations_all = __toESM(require_operations_all()), import_operations
5278
5388
  };
5279
5389
 
5280
5390
  // src/flat-configs.ts
5281
- var languageOptions = {
5282
- parser: { parseForESLint }
5283
- }, flatConfigs = {
5391
+ var languageOptions = { parser }, flatConfigs = {
5284
5392
  "operations-all": {
5285
5393
  languageOptions,
5286
5394
  rules: {
@@ -5309,10 +5417,7 @@ var languageOptions = {
5309
5417
  }
5310
5418
  };
5311
5419
  export {
5312
- configs,
5313
5420
  flatConfigs,
5314
- parseForESLint,
5315
- requireGraphQLSchemaFromContext,
5316
- requireSiblingsOperations,
5421
+ parser,
5317
5422
  rules
5318
5423
  };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.2",
4
+ "type": "module",
4
5
  "description": "GraphQL plugin for ESLint",
5
6
  "repository": "https://github.com/B2o5T/graphql-eslint",
6
7
  "author": "Dotan Simha <dotansimha@gmail.com>",
@@ -12,21 +13,21 @@
12
13
  "exports": {
13
14
  "./package.json": "./package.json",
14
15
  ".": {
15
- "browser": "./index.browser.mjs",
16
16
  "require": {
17
17
  "types": "./cjs/index.d.ts",
18
18
  "default": "./cjs/index.js"
19
19
  },
20
20
  "import": {
21
- "types": "./esm/index.d.mts",
21
+ "types": "./esm/index.d.ts",
22
22
  "default": "./esm/index.js"
23
23
  },
24
24
  "default": {
25
- "types": "./esm/index.d.mts",
25
+ "types": "./esm/index.d.ts",
26
26
  "default": "./esm/index.js"
27
27
  }
28
28
  }
29
29
  },
30
+ "types": "esm/index.d.ts",
30
31
  "keywords": [
31
32
  "eslint",
32
33
  "eslintplugin",
@@ -1,174 +0,0 @@
1
- declare const configs: {
2
- 'schema-recommended': {
3
- parser: string;
4
- plugins: string[];
5
- rules: {
6
- '@graphql-eslint/description-style': string;
7
- '@graphql-eslint/known-argument-names': string;
8
- '@graphql-eslint/known-directives': string;
9
- '@graphql-eslint/known-type-names': string;
10
- '@graphql-eslint/lone-schema-definition': string;
11
- '@graphql-eslint/naming-convention': (string | {
12
- types: string;
13
- FieldDefinition: string;
14
- InputValueDefinition: string;
15
- Argument: string;
16
- DirectiveDefinition: string;
17
- EnumValueDefinition: string;
18
- 'FieldDefinition[parent.name.value=Query]': {
19
- forbiddenPrefixes: string[];
20
- forbiddenSuffixes: string[];
21
- };
22
- 'FieldDefinition[parent.name.value=Mutation]': {
23
- forbiddenPrefixes: string[];
24
- forbiddenSuffixes: string[];
25
- };
26
- 'FieldDefinition[parent.name.value=Subscription]': {
27
- forbiddenPrefixes: string[];
28
- forbiddenSuffixes: string[];
29
- };
30
- 'EnumTypeDefinition,EnumTypeExtension': {
31
- forbiddenPrefixes: string[];
32
- forbiddenSuffixes: string[];
33
- };
34
- 'InterfaceTypeDefinition,InterfaceTypeExtension': {
35
- forbiddenPrefixes: string[];
36
- forbiddenSuffixes: string[];
37
- };
38
- 'UnionTypeDefinition,UnionTypeExtension': {
39
- forbiddenPrefixes: string[];
40
- forbiddenSuffixes: string[];
41
- };
42
- 'ObjectTypeDefinition,ObjectTypeExtension': {
43
- forbiddenPrefixes: string[];
44
- forbiddenSuffixes: string[];
45
- };
46
- })[];
47
- '@graphql-eslint/no-hashtag-description': string;
48
- '@graphql-eslint/no-typename-prefix': string;
49
- '@graphql-eslint/no-unreachable-types': string;
50
- '@graphql-eslint/possible-type-extension': string;
51
- '@graphql-eslint/provided-required-arguments': string;
52
- '@graphql-eslint/require-deprecation-reason': string;
53
- '@graphql-eslint/require-description': (string | {
54
- types: boolean;
55
- DirectiveDefinition: boolean;
56
- rootField: boolean;
57
- })[];
58
- '@graphql-eslint/strict-id-in-types': string;
59
- '@graphql-eslint/unique-directive-names': string;
60
- '@graphql-eslint/unique-directive-names-per-location': string;
61
- '@graphql-eslint/unique-enum-value-names': string;
62
- '@graphql-eslint/unique-field-definition-names': string;
63
- '@graphql-eslint/unique-operation-types': string;
64
- '@graphql-eslint/unique-type-names': string;
65
- };
66
- };
67
- 'schema-all': {
68
- extends: string;
69
- rules: {
70
- '@graphql-eslint/alphabetize': (string | {
71
- definitions: boolean;
72
- fields: string[];
73
- values: boolean;
74
- arguments: string[];
75
- groups: string[];
76
- })[];
77
- '@graphql-eslint/input-name': string;
78
- '@graphql-eslint/no-root-type': (string | {
79
- disallow: string[];
80
- })[];
81
- '@graphql-eslint/no-scalar-result-type-on-mutation': string;
82
- '@graphql-eslint/require-deprecation-date': string;
83
- '@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
84
- '@graphql-eslint/require-nullable-fields-with-oneof': string;
85
- '@graphql-eslint/require-nullable-result-in-root': string;
86
- '@graphql-eslint/require-type-pattern-with-oneof': string;
87
- };
88
- };
89
- 'schema-relay': {
90
- parser: string;
91
- plugins: string[];
92
- rules: {
93
- '@graphql-eslint/relay-arguments': string;
94
- '@graphql-eslint/relay-connection-types': string;
95
- '@graphql-eslint/relay-edge-types': string;
96
- '@graphql-eslint/relay-page-info': string;
97
- };
98
- };
99
- 'operations-recommended': {
100
- parser: string;
101
- plugins: string[];
102
- rules: {
103
- '@graphql-eslint/executable-definitions': string;
104
- '@graphql-eslint/fields-on-correct-type': string;
105
- '@graphql-eslint/fragments-on-composite-type': string;
106
- '@graphql-eslint/known-argument-names': string;
107
- '@graphql-eslint/known-directives': string;
108
- '@graphql-eslint/known-fragment-names': string;
109
- '@graphql-eslint/known-type-names': string;
110
- '@graphql-eslint/lone-anonymous-operation': string;
111
- '@graphql-eslint/naming-convention': (string | {
112
- VariableDefinition: string;
113
- OperationDefinition: {
114
- style: string;
115
- forbiddenPrefixes: string[];
116
- forbiddenSuffixes: string[];
117
- };
118
- FragmentDefinition: {
119
- style: string;
120
- forbiddenPrefixes: string[];
121
- forbiddenSuffixes: string[];
122
- };
123
- })[];
124
- '@graphql-eslint/no-anonymous-operations': string;
125
- '@graphql-eslint/no-deprecated': string;
126
- '@graphql-eslint/no-duplicate-fields': string;
127
- '@graphql-eslint/no-fragment-cycles': string;
128
- '@graphql-eslint/no-undefined-variables': string;
129
- '@graphql-eslint/no-unused-fragments': string;
130
- '@graphql-eslint/no-unused-variables': string;
131
- '@graphql-eslint/one-field-subscriptions': string;
132
- '@graphql-eslint/overlapping-fields-can-be-merged': string;
133
- '@graphql-eslint/possible-fragment-spread': string;
134
- '@graphql-eslint/provided-required-arguments': string;
135
- '@graphql-eslint/require-selections': string;
136
- '@graphql-eslint/scalar-leafs': string;
137
- '@graphql-eslint/selection-set-depth': (string | {
138
- maxDepth: number;
139
- })[];
140
- '@graphql-eslint/unique-argument-names': string;
141
- '@graphql-eslint/unique-directive-names-per-location': string;
142
- '@graphql-eslint/unique-fragment-name': string;
143
- '@graphql-eslint/unique-input-field-names': string;
144
- '@graphql-eslint/unique-operation-name': string;
145
- '@graphql-eslint/unique-variable-names': string;
146
- '@graphql-eslint/value-literals-of-correct-type': string;
147
- '@graphql-eslint/variables-are-input-types': string;
148
- '@graphql-eslint/variables-in-allowed-position': string;
149
- };
150
- };
151
- 'operations-all': {
152
- extends: string;
153
- rules: {
154
- '@graphql-eslint/alphabetize': (string | {
155
- definitions: boolean;
156
- selections: string[];
157
- variables: boolean;
158
- arguments: string[];
159
- groups: string[];
160
- })[];
161
- '@graphql-eslint/lone-executable-definition': string;
162
- '@graphql-eslint/match-document-filename': (string | {
163
- query: string;
164
- mutation: string;
165
- subscription: string;
166
- fragment: string;
167
- })[];
168
- '@graphql-eslint/no-one-place-fragments': string;
169
- '@graphql-eslint/require-import-fragment': string;
170
- };
171
- };
172
- };
173
-
174
- export { configs };