@graphql-eslint/eslint-plugin 4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561 → 4.3.1-alpha-20241209185034-de2d7397da8c26620a8930dd12b6dff42e43f537

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -408,7 +408,7 @@ function convertToESTree(node, schema16) {
408
408
  }
409
409
 
410
410
  // src/meta.ts
411
- var version = "4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561";
411
+ var version = "4.3.1-alpha-20241209185034-de2d7397da8c26620a8930dd12b6dff42e43f537";
412
412
 
413
413
  // src/siblings.ts
414
414
  import {
@@ -2124,19 +2124,18 @@ var CASE_STYLES = [
2124
2124
  var schemaOption = {
2125
2125
  oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asObject" }]
2126
2126
  };
2127
- var caseSchema = {
2128
- enum: CASE_STYLES,
2129
- description: `One of: ${CASE_STYLES.map((t) => `\`${t}\``).join(", ")}`
2130
- };
2131
2127
  var schema5 = {
2132
2128
  definitions: {
2133
- asString: caseSchema,
2129
+ asString: {
2130
+ enum: CASE_STYLES,
2131
+ description: `One of: ${CASE_STYLES.map((t) => `\`${t}\``).join(", ")}`
2132
+ },
2134
2133
  asObject: {
2135
2134
  type: "object",
2136
2135
  additionalProperties: false,
2137
2136
  minProperties: 1,
2138
2137
  properties: {
2139
- style: caseSchema,
2138
+ style: { enum: CASE_STYLES },
2140
2139
  suffix: { type: "string" },
2141
2140
  prefix: { type: "string" }
2142
2141
  }
@@ -2396,21 +2395,20 @@ var ALLOWED_STYLES = Object.keys(StyleToRegex);
2396
2395
  var schemaOption2 = {
2397
2396
  oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asObject" }]
2398
2397
  };
2399
- var descriptionPrefixesSuffixes = (name, id) => `> [!WARNING]
2398
+ var descriptionPrefixesSuffixes = (name) => `> [!WARNING]
2400
2399
  >
2401
- > This option is deprecated and will be removed in the next major release. Use [\`${name}\`](#${id}) instead.`;
2402
- var caseSchema2 = {
2403
- enum: ALLOWED_STYLES,
2404
- description: `One of: ${ALLOWED_STYLES.map((t) => `\`${t}\``).join(", ")}`
2405
- };
2400
+ > This option is deprecated and will be removed in the next major release. Use [\`${name}\`](#${name.toLowerCase()}-array) instead.`;
2406
2401
  var schema6 = {
2407
2402
  definitions: {
2408
- asString: caseSchema2,
2403
+ asString: {
2404
+ enum: ALLOWED_STYLES,
2405
+ description: `One of: ${ALLOWED_STYLES.map((t) => `\`${t}\``).join(", ")}`
2406
+ },
2409
2407
  asObject: {
2410
2408
  type: "object",
2411
2409
  additionalProperties: false,
2412
2410
  properties: {
2413
- style: caseSchema2,
2411
+ style: { enum: ALLOWED_STYLES },
2414
2412
  prefix: { type: "string" },
2415
2413
  suffix: { type: "string" },
2416
2414
  forbiddenPatterns: {
@@ -2420,25 +2418,28 @@ var schema6 = {
2420
2418
  },
2421
2419
  description: "Should be of instance of `RegEx`"
2422
2420
  },
2423
- requiredPattern: {
2424
- type: "object",
2421
+ requiredPatterns: {
2422
+ ...ARRAY_DEFAULT_OPTIONS,
2423
+ items: {
2424
+ type: "object"
2425
+ },
2425
2426
  description: "Should be of instance of `RegEx`"
2426
2427
  },
2427
2428
  forbiddenPrefixes: {
2428
2429
  ...ARRAY_DEFAULT_OPTIONS,
2429
- description: descriptionPrefixesSuffixes("forbiddenPatterns", "forbiddenpatterns-array")
2430
+ description: descriptionPrefixesSuffixes("forbiddenPatterns")
2430
2431
  },
2431
2432
  forbiddenSuffixes: {
2432
2433
  ...ARRAY_DEFAULT_OPTIONS,
2433
- description: descriptionPrefixesSuffixes("forbiddenPatterns", "forbiddenpatterns-array")
2434
+ description: descriptionPrefixesSuffixes("forbiddenPatterns")
2434
2435
  },
2435
2436
  requiredPrefixes: {
2436
2437
  ...ARRAY_DEFAULT_OPTIONS,
2437
- description: descriptionPrefixesSuffixes("requiredPattern", "requiredpattern-object")
2438
+ description: descriptionPrefixesSuffixes("requiredPatterns")
2438
2439
  },
2439
2440
  requiredSuffixes: {
2440
2441
  ...ARRAY_DEFAULT_OPTIONS,
2441
- description: descriptionPrefixesSuffixes("requiredPattern", "requiredpattern-object")
2442
+ description: descriptionPrefixesSuffixes("requiredPatterns")
2442
2443
  },
2443
2444
  ignorePattern: {
2444
2445
  type: "string",
@@ -2630,30 +2631,6 @@ var rule6 = {
2630
2631
  }
2631
2632
  `
2632
2633
  )
2633
- },
2634
- {
2635
- title: "Correct (Relay fragment convention `<module_name>_<property_name>`)",
2636
- usage: [
2637
- {
2638
- FragmentDefinition: {
2639
- style: "PascalCase",
2640
- requiredPattern: /_(?<camelCase>.+?)$/
2641
- }
2642
- }
2643
- ],
2644
- code: (
2645
- /* GraphQL */
2646
- `
2647
- # schema
2648
- type User {
2649
- # ...
2650
- }
2651
- # operations
2652
- fragment UserFields_data on User {
2653
- # ...
2654
- }
2655
- `
2656
- )
2657
2634
  }
2658
2635
  ],
2659
2636
  configOptions: {
@@ -2748,7 +2725,7 @@ var rule6 = {
2748
2725
  requiredPrefixes,
2749
2726
  requiredSuffixes,
2750
2727
  forbiddenPatterns,
2751
- requiredPattern
2728
+ requiredPatterns
2752
2729
  } = normalisePropertyOption(selector);
2753
2730
  const nodeName = node.value;
2754
2731
  const error = getError();
@@ -2767,9 +2744,7 @@ var rule6 = {
2767
2744
  );
2768
2745
  }
2769
2746
  function getError() {
2770
- let name = nodeName;
2771
- if (allowLeadingUnderscore) name = name.replace(/^_+/, "");
2772
- if (allowTrailingUnderscore) name = name.replace(/_+$/, "");
2747
+ const name = nodeName.replace(/(^_+)|(_+$)/g, "");
2773
2748
  if (ignorePattern && new RegExp(ignorePattern, "u").test(name)) {
2774
2749
  if ("name" in n) {
2775
2750
  ignoredNodes.add(n.name);
@@ -2788,38 +2763,6 @@ var rule6 = {
2788
2763
  renameToNames: [name + suffix]
2789
2764
  };
2790
2765
  }
2791
- if (requiredPattern) {
2792
- if (requiredPattern.source.includes("(?<")) {
2793
- try {
2794
- name = name.replace(requiredPattern, (originalString, ...args) => {
2795
- const groups = args.at(-1);
2796
- for (const [styleName, value] of Object.entries(groups)) {
2797
- if (!(styleName in StyleToRegex)) {
2798
- throw new Error("Invalid case style in `requiredPatterns` option");
2799
- }
2800
- if (value === convertCase(styleName, value)) {
2801
- return "";
2802
- }
2803
- throw new Error(`contain the required pattern: ${requiredPattern}`);
2804
- }
2805
- return originalString;
2806
- });
2807
- if (name === nodeName) {
2808
- throw new Error(`contain the required pattern: ${requiredPattern}`);
2809
- }
2810
- } catch (error2) {
2811
- return {
2812
- errorMessage: error2.message,
2813
- renameToNames: []
2814
- };
2815
- }
2816
- } else if (!requiredPattern.test(name)) {
2817
- return {
2818
- errorMessage: `contain the required pattern: ${requiredPattern}`,
2819
- renameToNames: []
2820
- };
2821
- }
2822
- }
2823
2766
  const forbidden = forbiddenPatterns?.find((pattern) => pattern.test(name));
2824
2767
  if (forbidden) {
2825
2768
  return {
@@ -2827,6 +2770,12 @@ var rule6 = {
2827
2770
  renameToNames: [name.replace(forbidden, "")]
2828
2771
  };
2829
2772
  }
2773
+ if (requiredPatterns && !requiredPatterns.some((pattern) => pattern.test(name))) {
2774
+ return {
2775
+ errorMessage: `contain the required pattern: ${englishJoinWords(requiredPatterns.map((re) => re.source))}`,
2776
+ renameToNames: []
2777
+ };
2778
+ }
2830
2779
  const forbiddenPrefix = forbiddenPrefixes?.find((prefix2) => name.startsWith(prefix2));
2831
2780
  if (forbiddenPrefix) {
2832
2781
  return {
@@ -4807,22 +4756,6 @@ var ALLOWED_KINDS2 = [
4807
4756
  Kind17.ENUM_VALUE_DEFINITION,
4808
4757
  Kind17.OPERATION_DEFINITION
4809
4758
  ];
4810
- var entries = /* @__PURE__ */ Object.create(null);
4811
- for (const kind of [...ALLOWED_KINDS2].sort()) {
4812
- let description = `> [!NOTE]
4813
- >
4814
- > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
4815
- if (kind === Kind17.OPERATION_DEFINITION) {
4816
- description += [
4817
- "",
4818
- "",
4819
- "> [!WARNING]",
4820
- ">",
4821
- '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'
4822
- ].join("\n");
4823
- }
4824
- entries[kind] = { type: "boolean", description };
4825
- }
4826
4759
  var schema12 = {
4827
4760
  type: "array",
4828
4761
  minItems: 1,
@@ -4847,7 +4780,23 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
4847
4780
  ...ARRAY_DEFAULT_OPTIONS,
4848
4781
  description: ["Ignore specific selectors", eslintSelectorsTip].join("\n")
4849
4782
  },
4850
- ...entries
4783
+ ...Object.fromEntries(
4784
+ [...ALLOWED_KINDS2].sort().map((kind) => {
4785
+ let description = `> [!NOTE]
4786
+ >
4787
+ > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
4788
+ if (kind === Kind17.OPERATION_DEFINITION) {
4789
+ description += [
4790
+ "",
4791
+ "",
4792
+ "> [!WARNING]",
4793
+ ">",
4794
+ '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'
4795
+ ].join("\n");
4796
+ }
4797
+ return [kind, { type: "boolean", description }];
4798
+ })
4799
+ )
4851
4800
  }
4852
4801
  }
4853
4802
  };
package/cjs/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ import { RuleOptions } from './rules/require-description/index.cjs';
1
2
  import { CaseStyle } from './utils.cjs';
2
3
  export { requireGraphQLOperations, requireGraphQLSchema } from './utils.cjs';
3
4
  import * as graphql from 'graphql';
@@ -100,9 +101,9 @@ declare const _default: {
100
101
  forbiddenPatterns?: {
101
102
  [x: string]: unknown;
102
103
  }[] | undefined;
103
- requiredPattern?: {
104
+ requiredPatterns?: {
104
105
  [x: string]: unknown;
105
- } | undefined;
106
+ }[] | undefined;
106
107
  forbiddenPrefixes?: string[] | undefined;
107
108
  forbiddenSuffixes?: string[] | undefined;
108
109
  requiredPrefixes?: string[] | undefined;
@@ -140,22 +141,7 @@ declare const _default: {
140
141
  argumentName?: string | undefined;
141
142
  }[]>;
142
143
  'require-deprecation-reason': GraphQLESLintRule;
143
- 'require-description': GraphQLESLintRule<{
144
- types?: true | undefined;
145
- OperationDefinition?: boolean | undefined;
146
- ScalarTypeDefinition?: boolean | undefined;
147
- ObjectTypeDefinition?: boolean | undefined;
148
- FieldDefinition?: boolean | undefined;
149
- InputValueDefinition?: boolean | undefined;
150
- InterfaceTypeDefinition?: boolean | undefined;
151
- UnionTypeDefinition?: boolean | undefined;
152
- EnumTypeDefinition?: boolean | undefined;
153
- EnumValueDefinition?: boolean | undefined;
154
- InputObjectTypeDefinition?: boolean | undefined;
155
- DirectiveDefinition?: boolean | undefined;
156
- rootField?: true | undefined;
157
- ignoredSelectors?: string[] | undefined;
158
- }[]>;
144
+ 'require-description': GraphQLESLintRule<RuleOptions>;
159
145
  'require-field-of-type-query-in-mutation-result': GraphQLESLintRule;
160
146
  'require-import-fragment': GraphQLESLintRule;
161
147
  'require-nullable-fields-with-oneof': GraphQLESLintRule;
package/cjs/meta.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});const version = "4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561";
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});const version = "4.3.1-alpha-20241209185034-de2d7397da8c26620a8930dd12b6dff42e43f537";
2
2
 
3
3
 
4
4
  exports.version = version;
@@ -1,3 +1,4 @@
1
+ import { RuleOptions } from './require-description/index.cjs';
1
2
  import { CaseStyle } from '../utils.cjs';
2
3
  import * as graphql from 'graphql';
3
4
  import { GraphQLESLintRule } from '../types.cjs';
@@ -63,9 +64,9 @@ declare const rules: {
63
64
  forbiddenPatterns?: {
64
65
  [x: string]: unknown;
65
66
  }[] | undefined;
66
- requiredPattern?: {
67
+ requiredPatterns?: {
67
68
  [x: string]: unknown;
68
- } | undefined;
69
+ }[] | undefined;
69
70
  forbiddenPrefixes?: string[] | undefined;
70
71
  forbiddenSuffixes?: string[] | undefined;
71
72
  requiredPrefixes?: string[] | undefined;
@@ -103,22 +104,7 @@ declare const rules: {
103
104
  argumentName?: string | undefined;
104
105
  }[]>;
105
106
  'require-deprecation-reason': GraphQLESLintRule;
106
- 'require-description': GraphQLESLintRule<{
107
- types?: true | undefined;
108
- OperationDefinition?: boolean | undefined;
109
- ScalarTypeDefinition?: boolean | undefined;
110
- ObjectTypeDefinition?: boolean | undefined;
111
- FieldDefinition?: boolean | undefined;
112
- InputValueDefinition?: boolean | undefined;
113
- InterfaceTypeDefinition?: boolean | undefined;
114
- UnionTypeDefinition?: boolean | undefined;
115
- EnumTypeDefinition?: boolean | undefined;
116
- EnumValueDefinition?: boolean | undefined;
117
- InputObjectTypeDefinition?: boolean | undefined;
118
- DirectiveDefinition?: boolean | undefined;
119
- rootField?: true | undefined;
120
- ignoredSelectors?: string[] | undefined;
121
- }[]>;
107
+ 'require-description': GraphQLESLintRule<RuleOptions>;
122
108
  'require-field-of-type-query-in-mutation-result': GraphQLESLintRule;
123
109
  'require-import-fragment': GraphQLESLintRule;
124
110
  'require-nullable-fields-with-oneof': GraphQLESLintRule;
@@ -13,8 +13,8 @@ type CaseStyle = CaseStyle$1 | 'matchDocumentStyle';
13
13
  declare const schema: {
14
14
  readonly definitions: {
15
15
  readonly asString: {
16
- enum: CaseStyle[];
17
- description: string;
16
+ readonly enum: CaseStyle[];
17
+ readonly description: `One of: ${string}`;
18
18
  };
19
19
  readonly asObject: {
20
20
  readonly type: "object";
@@ -22,8 +22,7 @@ declare const schema: {
22
22
  readonly minProperties: 1;
23
23
  readonly properties: {
24
24
  readonly style: {
25
- enum: CaseStyle[];
26
- description: string;
25
+ readonly enum: CaseStyle[];
27
26
  };
28
27
  readonly suffix: {
29
28
  readonly type: "string";
@@ -18,19 +18,18 @@ const CASE_STYLES = [
18
18
  const schemaOption = {
19
19
  oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asObject" }]
20
20
  };
21
- const caseSchema = {
22
- enum: CASE_STYLES,
23
- description: `One of: ${CASE_STYLES.map((t) => `\`${t}\``).join(", ")}`
24
- };
25
21
  const schema = {
26
22
  definitions: {
27
- asString: caseSchema,
23
+ asString: {
24
+ enum: CASE_STYLES,
25
+ description: `One of: ${CASE_STYLES.map((t) => `\`${t}\``).join(", ")}`
26
+ },
28
27
  asObject: {
29
28
  type: "object",
30
29
  additionalProperties: false,
31
30
  minProperties: 1,
32
31
  properties: {
33
- style: caseSchema,
32
+ style: { enum: CASE_STYLES },
34
33
  suffix: { type: "string" },
35
34
  prefix: { type: "string" }
36
35
  }
@@ -12,16 +12,15 @@ type AllowedStyle = 'camelCase' | 'PascalCase' | 'snake_case' | 'UPPER_CASE';
12
12
  declare const schema: {
13
13
  readonly definitions: {
14
14
  readonly asString: {
15
- enum: AllowedStyle[];
16
- description: string;
15
+ readonly enum: AllowedStyle[];
16
+ readonly description: `One of: ${string}`;
17
17
  };
18
18
  readonly asObject: {
19
19
  readonly type: "object";
20
20
  readonly additionalProperties: false;
21
21
  readonly properties: {
22
22
  readonly style: {
23
- enum: AllowedStyle[];
24
- description: string;
23
+ readonly enum: AllowedStyle[];
25
24
  };
26
25
  readonly prefix: {
27
26
  readonly type: "string";
@@ -38,9 +37,14 @@ declare const schema: {
38
37
  readonly uniqueItems: true;
39
38
  readonly minItems: 1;
40
39
  };
41
- readonly requiredPattern: {
42
- readonly type: "object";
40
+ readonly requiredPatterns: {
41
+ readonly items: {
42
+ readonly type: "object";
43
+ };
43
44
  readonly description: "Should be of instance of `RegEx`";
45
+ readonly type: "array";
46
+ readonly uniqueItems: true;
47
+ readonly minItems: 1;
44
48
  };
45
49
  readonly forbiddenPrefixes: {
46
50
  readonly description: string;
@@ -36,21 +36,20 @@ const ALLOWED_STYLES = Object.keys(StyleToRegex);
36
36
  const schemaOption = {
37
37
  oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asObject" }]
38
38
  };
39
- const descriptionPrefixesSuffixes = (name, id) => `> [!WARNING]
39
+ const descriptionPrefixesSuffixes = (name) => `> [!WARNING]
40
40
  >
41
- > This option is deprecated and will be removed in the next major release. Use [\`${name}\`](#${id}) instead.`;
42
- const caseSchema = {
43
- enum: ALLOWED_STYLES,
44
- description: `One of: ${ALLOWED_STYLES.map((t) => `\`${t}\``).join(", ")}`
45
- };
41
+ > This option is deprecated and will be removed in the next major release. Use [\`${name}\`](#${name.toLowerCase()}-array) instead.`;
46
42
  const schema = {
47
43
  definitions: {
48
- asString: caseSchema,
44
+ asString: {
45
+ enum: ALLOWED_STYLES,
46
+ description: `One of: ${ALLOWED_STYLES.map((t) => `\`${t}\``).join(", ")}`
47
+ },
49
48
  asObject: {
50
49
  type: "object",
51
50
  additionalProperties: false,
52
51
  properties: {
53
- style: caseSchema,
52
+ style: { enum: ALLOWED_STYLES },
54
53
  prefix: { type: "string" },
55
54
  suffix: { type: "string" },
56
55
  forbiddenPatterns: {
@@ -60,25 +59,28 @@ const schema = {
60
59
  },
61
60
  description: "Should be of instance of `RegEx`"
62
61
  },
63
- requiredPattern: {
64
- type: "object",
62
+ requiredPatterns: {
63
+ ..._utilsjs.ARRAY_DEFAULT_OPTIONS,
64
+ items: {
65
+ type: "object"
66
+ },
65
67
  description: "Should be of instance of `RegEx`"
66
68
  },
67
69
  forbiddenPrefixes: {
68
70
  ..._utilsjs.ARRAY_DEFAULT_OPTIONS,
69
- description: descriptionPrefixesSuffixes("forbiddenPatterns", "forbiddenpatterns-array")
71
+ description: descriptionPrefixesSuffixes("forbiddenPatterns")
70
72
  },
71
73
  forbiddenSuffixes: {
72
74
  ..._utilsjs.ARRAY_DEFAULT_OPTIONS,
73
- description: descriptionPrefixesSuffixes("forbiddenPatterns", "forbiddenpatterns-array")
75
+ description: descriptionPrefixesSuffixes("forbiddenPatterns")
74
76
  },
75
77
  requiredPrefixes: {
76
78
  ..._utilsjs.ARRAY_DEFAULT_OPTIONS,
77
- description: descriptionPrefixesSuffixes("requiredPattern", "requiredpattern-object")
79
+ description: descriptionPrefixesSuffixes("requiredPatterns")
78
80
  },
79
81
  requiredSuffixes: {
80
82
  ..._utilsjs.ARRAY_DEFAULT_OPTIONS,
81
- description: descriptionPrefixesSuffixes("requiredPattern", "requiredpattern-object")
83
+ description: descriptionPrefixesSuffixes("requiredPatterns")
82
84
  },
83
85
  ignorePattern: {
84
86
  type: "string",
@@ -270,30 +272,6 @@ const rule = {
270
272
  }
271
273
  `
272
274
  )
273
- },
274
- {
275
- title: "Correct (Relay fragment convention `<module_name>_<property_name>`)",
276
- usage: [
277
- {
278
- FragmentDefinition: {
279
- style: "PascalCase",
280
- requiredPattern: /_(?<camelCase>.+?)$/
281
- }
282
- }
283
- ],
284
- code: (
285
- /* GraphQL */
286
- `
287
- # schema
288
- type User {
289
- # ...
290
- }
291
- # operations
292
- fragment UserFields_data on User {
293
- # ...
294
- }
295
- `
296
- )
297
275
  }
298
276
  ],
299
277
  configOptions: {
@@ -388,7 +366,7 @@ const rule = {
388
366
  requiredPrefixes,
389
367
  requiredSuffixes,
390
368
  forbiddenPatterns,
391
- requiredPattern
369
+ requiredPatterns
392
370
  } = normalisePropertyOption(selector);
393
371
  const nodeName = node.value;
394
372
  const error = getError();
@@ -407,9 +385,7 @@ const rule = {
407
385
  );
408
386
  }
409
387
  function getError() {
410
- let name = nodeName;
411
- if (allowLeadingUnderscore) name = name.replace(/^_+/, "");
412
- if (allowTrailingUnderscore) name = name.replace(/_+$/, "");
388
+ const name = nodeName.replace(/(^_+)|(_+$)/g, "");
413
389
  if (ignorePattern && new RegExp(ignorePattern, "u").test(name)) {
414
390
  if ("name" in n) {
415
391
  ignoredNodes.add(n.name);
@@ -428,38 +404,6 @@ const rule = {
428
404
  renameToNames: [name + suffix]
429
405
  };
430
406
  }
431
- if (requiredPattern) {
432
- if (requiredPattern.source.includes("(?<")) {
433
- try {
434
- name = name.replace(requiredPattern, (originalString, ...args) => {
435
- const groups = args.at(-1);
436
- for (const [styleName, value] of Object.entries(groups)) {
437
- if (!(styleName in StyleToRegex)) {
438
- throw new Error("Invalid case style in `requiredPatterns` option");
439
- }
440
- if (value === _utilsjs.convertCase.call(void 0, styleName, value)) {
441
- return "";
442
- }
443
- throw new Error(`contain the required pattern: ${requiredPattern}`);
444
- }
445
- return originalString;
446
- });
447
- if (name === nodeName) {
448
- throw new Error(`contain the required pattern: ${requiredPattern}`);
449
- }
450
- } catch (error2) {
451
- return {
452
- errorMessage: error2.message,
453
- renameToNames: []
454
- };
455
- }
456
- } else if (!requiredPattern.test(name)) {
457
- return {
458
- errorMessage: `contain the required pattern: ${requiredPattern}`,
459
- renameToNames: []
460
- };
461
- }
462
- }
463
407
  const forbidden = _optionalChain([forbiddenPatterns, 'optionalAccess', _ => _.find, 'call', _2 => _2((pattern) => pattern.test(name))]);
464
408
  if (forbidden) {
465
409
  return {
@@ -467,6 +411,12 @@ const rule = {
467
411
  renameToNames: [name.replace(forbidden, "")]
468
412
  };
469
413
  }
414
+ if (requiredPatterns && !requiredPatterns.some((pattern) => pattern.test(name))) {
415
+ return {
416
+ errorMessage: `contain the required pattern: ${_utilsjs.englishJoinWords.call(void 0, requiredPatterns.map((re) => re.source))}`,
417
+ renameToNames: []
418
+ };
419
+ }
470
420
  const forbiddenPrefix = _optionalChain([forbiddenPrefixes, 'optionalAccess', _3 => _3.find, 'call', _4 => _4((prefix2) => name.startsWith(prefix2))]);
471
421
  if (forbiddenPrefix) {
472
422
  return {
@@ -1,91 +1,25 @@
1
- import { FromSchema } from 'json-schema-to-ts';
1
+ import { Kind } from 'graphql';
2
2
  import { GraphQLESLintRule } from '../../types.cjs';
3
3
  import 'eslint';
4
4
  import 'estree';
5
- import 'graphql';
6
5
  import 'graphql-config';
6
+ import 'json-schema-to-ts';
7
7
  import '../../estree-converter/types.cjs';
8
8
  import '../../siblings.cjs';
9
9
  import '@graphql-tools/utils';
10
10
 
11
11
  declare const RULE_ID = "require-description";
12
- declare const schema: {
13
- readonly type: "array";
14
- readonly minItems: 1;
15
- readonly maxItems: 1;
16
- readonly items: {
17
- readonly type: "object";
18
- readonly additionalProperties: false;
19
- readonly minProperties: 1;
20
- readonly properties: {
21
- readonly OperationDefinition: {
22
- type: "boolean";
23
- description: string;
24
- };
25
- readonly ScalarTypeDefinition: {
26
- type: "boolean";
27
- description: string;
28
- };
29
- readonly ObjectTypeDefinition: {
30
- type: "boolean";
31
- description: string;
32
- };
33
- readonly FieldDefinition: {
34
- type: "boolean";
35
- description: string;
36
- };
37
- readonly InputValueDefinition: {
38
- type: "boolean";
39
- description: string;
40
- };
41
- readonly InterfaceTypeDefinition: {
42
- type: "boolean";
43
- description: string;
44
- };
45
- readonly UnionTypeDefinition: {
46
- type: "boolean";
47
- description: string;
48
- };
49
- readonly EnumTypeDefinition: {
50
- type: "boolean";
51
- description: string;
52
- };
53
- readonly EnumValueDefinition: {
54
- type: "boolean";
55
- description: string;
56
- };
57
- readonly InputObjectTypeDefinition: {
58
- type: "boolean";
59
- description: string;
60
- };
61
- readonly DirectiveDefinition: {
62
- type: "boolean";
63
- description: string;
64
- };
65
- readonly types: {
66
- readonly type: "boolean";
67
- readonly enum: readonly [true];
68
- readonly description: `Includes:
69
- ${string}`;
70
- };
71
- readonly rootField: {
72
- readonly type: "boolean";
73
- readonly enum: readonly [true];
74
- readonly description: "Definitions within `Query`, `Mutation`, and `Subscription` root types.";
75
- };
76
- readonly ignoredSelectors: {
77
- readonly description: string;
78
- readonly type: "array";
79
- readonly uniqueItems: true;
80
- readonly minItems: 1;
81
- readonly items: {
82
- readonly type: "string";
83
- };
84
- };
85
- };
86
- };
87
- };
88
- type RuleOptions = FromSchema<typeof schema>;
12
+ declare const ALLOWED_KINDS: readonly [Kind.OBJECT_TYPE_DEFINITION, Kind.INTERFACE_TYPE_DEFINITION, Kind.ENUM_TYPE_DEFINITION, Kind.SCALAR_TYPE_DEFINITION, Kind.INPUT_OBJECT_TYPE_DEFINITION, Kind.UNION_TYPE_DEFINITION, Kind.DIRECTIVE_DEFINITION, Kind.FIELD_DEFINITION, Kind.INPUT_VALUE_DEFINITION, Kind.ENUM_VALUE_DEFINITION, Kind.OPERATION_DEFINITION];
13
+ type AllowedKind = (typeof ALLOWED_KINDS)[number];
14
+ type RuleOptions = [
15
+ {
16
+ [key in AllowedKind]?: boolean;
17
+ } & {
18
+ types?: true;
19
+ rootField?: true;
20
+ ignoredSelectors?: string[];
21
+ }
22
+ ];
89
23
  declare const rule: GraphQLESLintRule<RuleOptions>;
90
24
 
91
25
  export { RULE_ID, type RuleOptions, rule };
@@ -17,22 +17,6 @@ const ALLOWED_KINDS = [
17
17
  _graphql.Kind.ENUM_VALUE_DEFINITION,
18
18
  _graphql.Kind.OPERATION_DEFINITION
19
19
  ];
20
- const entries = /* @__PURE__ */ Object.create(null);
21
- for (const kind of [...ALLOWED_KINDS].sort()) {
22
- let description = `> [!NOTE]
23
- >
24
- > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
25
- if (kind === _graphql.Kind.OPERATION_DEFINITION) {
26
- description += [
27
- "",
28
- "",
29
- "> [!WARNING]",
30
- ">",
31
- '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'
32
- ].join("\n");
33
- }
34
- entries[kind] = { type: "boolean", description };
35
- }
36
20
  const schema = {
37
21
  type: "array",
38
22
  minItems: 1,
@@ -57,7 +41,23 @@ ${_utilsjs.TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
57
41
  ..._utilsjs.ARRAY_DEFAULT_OPTIONS,
58
42
  description: ["Ignore specific selectors", _utilsjs.eslintSelectorsTip].join("\n")
59
43
  },
60
- ...entries
44
+ ...Object.fromEntries(
45
+ [...ALLOWED_KINDS].sort().map((kind) => {
46
+ let description = `> [!NOTE]
47
+ >
48
+ > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
49
+ if (kind === _graphql.Kind.OPERATION_DEFINITION) {
50
+ description += [
51
+ "",
52
+ "",
53
+ "> [!WARNING]",
54
+ ">",
55
+ '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'
56
+ ].join("\n");
57
+ }
58
+ return [kind, { type: "boolean", description }];
59
+ })
60
+ )
61
61
  }
62
62
  }
63
63
  };
package/esm/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { RuleOptions } from './rules/require-description/index.js';
1
2
  import { CaseStyle } from './utils.js';
2
3
  export { requireGraphQLOperations, requireGraphQLSchema } from './utils.js';
3
4
  import * as graphql from 'graphql';
@@ -48,10 +49,10 @@ declare const _default: {
48
49
  };
49
50
  rules: {
50
51
  alphabetize: GraphQLESLintRule<{
51
- values?: boolean | undefined;
52
52
  definitions?: boolean | undefined;
53
53
  selections?: ("OperationDefinition" | "FragmentDefinition")[] | undefined;
54
54
  arguments?: ("Field" | "Directive" | "FieldDefinition" | "DirectiveDefinition")[] | undefined;
55
+ values?: boolean | undefined;
55
56
  fields?: ("ObjectTypeDefinition" | "InterfaceTypeDefinition" | "InputObjectTypeDefinition")[] | undefined;
56
57
  variables?: boolean | undefined;
57
58
  groups?: string[] | undefined;
@@ -100,9 +101,9 @@ declare const _default: {
100
101
  forbiddenPatterns?: {
101
102
  [x: string]: unknown;
102
103
  }[] | undefined;
103
- requiredPattern?: {
104
+ requiredPatterns?: {
104
105
  [x: string]: unknown;
105
- } | undefined;
106
+ }[] | undefined;
106
107
  forbiddenPrefixes?: string[] | undefined;
107
108
  forbiddenSuffixes?: string[] | undefined;
108
109
  requiredPrefixes?: string[] | undefined;
@@ -140,22 +141,7 @@ declare const _default: {
140
141
  argumentName?: string | undefined;
141
142
  }[]>;
142
143
  'require-deprecation-reason': GraphQLESLintRule;
143
- 'require-description': GraphQLESLintRule<{
144
- types?: true | undefined;
145
- OperationDefinition?: boolean | undefined;
146
- ScalarTypeDefinition?: boolean | undefined;
147
- ObjectTypeDefinition?: boolean | undefined;
148
- FieldDefinition?: boolean | undefined;
149
- InputValueDefinition?: boolean | undefined;
150
- InterfaceTypeDefinition?: boolean | undefined;
151
- UnionTypeDefinition?: boolean | undefined;
152
- EnumTypeDefinition?: boolean | undefined;
153
- EnumValueDefinition?: boolean | undefined;
154
- InputObjectTypeDefinition?: boolean | undefined;
155
- DirectiveDefinition?: boolean | undefined;
156
- rootField?: true | undefined;
157
- ignoredSelectors?: string[] | undefined;
158
- }[]>;
144
+ 'require-description': GraphQLESLintRule<RuleOptions>;
159
145
  'require-field-of-type-query-in-mutation-result': GraphQLESLintRule;
160
146
  'require-import-fragment': GraphQLESLintRule;
161
147
  'require-nullable-fields-with-oneof': GraphQLESLintRule;
package/esm/meta.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = "4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561";
1
+ const version = "4.3.1-alpha-20241209185034-de2d7397da8c26620a8930dd12b6dff42e43f537";
2
2
  export {
3
3
  version
4
4
  };
@@ -1,3 +1,4 @@
1
+ import { RuleOptions } from './require-description/index.js';
1
2
  import { CaseStyle } from '../utils.js';
2
3
  import * as graphql from 'graphql';
3
4
  import { GraphQLESLintRule } from '../types.js';
@@ -11,10 +12,10 @@ import 'json-schema-to-ts';
11
12
 
12
13
  declare const rules: {
13
14
  alphabetize: GraphQLESLintRule<{
14
- values?: boolean | undefined;
15
15
  definitions?: boolean | undefined;
16
16
  selections?: ("OperationDefinition" | "FragmentDefinition")[] | undefined;
17
17
  arguments?: ("Field" | "Directive" | "FieldDefinition" | "DirectiveDefinition")[] | undefined;
18
+ values?: boolean | undefined;
18
19
  fields?: ("ObjectTypeDefinition" | "InterfaceTypeDefinition" | "InputObjectTypeDefinition")[] | undefined;
19
20
  variables?: boolean | undefined;
20
21
  groups?: string[] | undefined;
@@ -63,9 +64,9 @@ declare const rules: {
63
64
  forbiddenPatterns?: {
64
65
  [x: string]: unknown;
65
66
  }[] | undefined;
66
- requiredPattern?: {
67
+ requiredPatterns?: {
67
68
  [x: string]: unknown;
68
- } | undefined;
69
+ }[] | undefined;
69
70
  forbiddenPrefixes?: string[] | undefined;
70
71
  forbiddenSuffixes?: string[] | undefined;
71
72
  requiredPrefixes?: string[] | undefined;
@@ -103,22 +104,7 @@ declare const rules: {
103
104
  argumentName?: string | undefined;
104
105
  }[]>;
105
106
  'require-deprecation-reason': GraphQLESLintRule;
106
- 'require-description': GraphQLESLintRule<{
107
- types?: true | undefined;
108
- OperationDefinition?: boolean | undefined;
109
- ScalarTypeDefinition?: boolean | undefined;
110
- ObjectTypeDefinition?: boolean | undefined;
111
- FieldDefinition?: boolean | undefined;
112
- InputValueDefinition?: boolean | undefined;
113
- InterfaceTypeDefinition?: boolean | undefined;
114
- UnionTypeDefinition?: boolean | undefined;
115
- EnumTypeDefinition?: boolean | undefined;
116
- EnumValueDefinition?: boolean | undefined;
117
- InputObjectTypeDefinition?: boolean | undefined;
118
- DirectiveDefinition?: boolean | undefined;
119
- rootField?: true | undefined;
120
- ignoredSelectors?: string[] | undefined;
121
- }[]>;
107
+ 'require-description': GraphQLESLintRule<RuleOptions>;
122
108
  'require-field-of-type-query-in-mutation-result': GraphQLESLintRule;
123
109
  'require-import-fragment': GraphQLESLintRule;
124
110
  'require-nullable-fields-with-oneof': GraphQLESLintRule;
@@ -13,8 +13,8 @@ type CaseStyle = CaseStyle$1 | 'matchDocumentStyle';
13
13
  declare const schema: {
14
14
  readonly definitions: {
15
15
  readonly asString: {
16
- enum: CaseStyle[];
17
- description: string;
16
+ readonly enum: CaseStyle[];
17
+ readonly description: `One of: ${string}`;
18
18
  };
19
19
  readonly asObject: {
20
20
  readonly type: "object";
@@ -22,8 +22,7 @@ declare const schema: {
22
22
  readonly minProperties: 1;
23
23
  readonly properties: {
24
24
  readonly style: {
25
- enum: CaseStyle[];
26
- description: string;
25
+ readonly enum: CaseStyle[];
27
26
  };
28
27
  readonly suffix: {
29
28
  readonly type: "string";
@@ -18,19 +18,18 @@ const CASE_STYLES = [
18
18
  const schemaOption = {
19
19
  oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asObject" }]
20
20
  };
21
- const caseSchema = {
22
- enum: CASE_STYLES,
23
- description: `One of: ${CASE_STYLES.map((t) => `\`${t}\``).join(", ")}`
24
- };
25
21
  const schema = {
26
22
  definitions: {
27
- asString: caseSchema,
23
+ asString: {
24
+ enum: CASE_STYLES,
25
+ description: `One of: ${CASE_STYLES.map((t) => `\`${t}\``).join(", ")}`
26
+ },
28
27
  asObject: {
29
28
  type: "object",
30
29
  additionalProperties: false,
31
30
  minProperties: 1,
32
31
  properties: {
33
- style: caseSchema,
32
+ style: { enum: CASE_STYLES },
34
33
  suffix: { type: "string" },
35
34
  prefix: { type: "string" }
36
35
  }
@@ -12,16 +12,15 @@ type AllowedStyle = 'camelCase' | 'PascalCase' | 'snake_case' | 'UPPER_CASE';
12
12
  declare const schema: {
13
13
  readonly definitions: {
14
14
  readonly asString: {
15
- enum: AllowedStyle[];
16
- description: string;
15
+ readonly enum: AllowedStyle[];
16
+ readonly description: `One of: ${string}`;
17
17
  };
18
18
  readonly asObject: {
19
19
  readonly type: "object";
20
20
  readonly additionalProperties: false;
21
21
  readonly properties: {
22
22
  readonly style: {
23
- enum: AllowedStyle[];
24
- description: string;
23
+ readonly enum: AllowedStyle[];
25
24
  };
26
25
  readonly prefix: {
27
26
  readonly type: "string";
@@ -38,9 +37,14 @@ declare const schema: {
38
37
  readonly uniqueItems: true;
39
38
  readonly minItems: 1;
40
39
  };
41
- readonly requiredPattern: {
42
- readonly type: "object";
40
+ readonly requiredPatterns: {
41
+ readonly items: {
42
+ readonly type: "object";
43
+ };
43
44
  readonly description: "Should be of instance of `RegEx`";
45
+ readonly type: "array";
46
+ readonly uniqueItems: true;
47
+ readonly minItems: 1;
44
48
  };
45
49
  readonly forbiddenPrefixes: {
46
50
  readonly description: string;
@@ -36,21 +36,20 @@ const ALLOWED_STYLES = Object.keys(StyleToRegex);
36
36
  const schemaOption = {
37
37
  oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asObject" }]
38
38
  };
39
- const descriptionPrefixesSuffixes = (name, id) => `> [!WARNING]
39
+ const descriptionPrefixesSuffixes = (name) => `> [!WARNING]
40
40
  >
41
- > This option is deprecated and will be removed in the next major release. Use [\`${name}\`](#${id}) instead.`;
42
- const caseSchema = {
43
- enum: ALLOWED_STYLES,
44
- description: `One of: ${ALLOWED_STYLES.map((t) => `\`${t}\``).join(", ")}`
45
- };
41
+ > This option is deprecated and will be removed in the next major release. Use [\`${name}\`](#${name.toLowerCase()}-array) instead.`;
46
42
  const schema = {
47
43
  definitions: {
48
- asString: caseSchema,
44
+ asString: {
45
+ enum: ALLOWED_STYLES,
46
+ description: `One of: ${ALLOWED_STYLES.map((t) => `\`${t}\``).join(", ")}`
47
+ },
49
48
  asObject: {
50
49
  type: "object",
51
50
  additionalProperties: false,
52
51
  properties: {
53
- style: caseSchema,
52
+ style: { enum: ALLOWED_STYLES },
54
53
  prefix: { type: "string" },
55
54
  suffix: { type: "string" },
56
55
  forbiddenPatterns: {
@@ -60,25 +59,28 @@ const schema = {
60
59
  },
61
60
  description: "Should be of instance of `RegEx`"
62
61
  },
63
- requiredPattern: {
64
- type: "object",
62
+ requiredPatterns: {
63
+ ...ARRAY_DEFAULT_OPTIONS,
64
+ items: {
65
+ type: "object"
66
+ },
65
67
  description: "Should be of instance of `RegEx`"
66
68
  },
67
69
  forbiddenPrefixes: {
68
70
  ...ARRAY_DEFAULT_OPTIONS,
69
- description: descriptionPrefixesSuffixes("forbiddenPatterns", "forbiddenpatterns-array")
71
+ description: descriptionPrefixesSuffixes("forbiddenPatterns")
70
72
  },
71
73
  forbiddenSuffixes: {
72
74
  ...ARRAY_DEFAULT_OPTIONS,
73
- description: descriptionPrefixesSuffixes("forbiddenPatterns", "forbiddenpatterns-array")
75
+ description: descriptionPrefixesSuffixes("forbiddenPatterns")
74
76
  },
75
77
  requiredPrefixes: {
76
78
  ...ARRAY_DEFAULT_OPTIONS,
77
- description: descriptionPrefixesSuffixes("requiredPattern", "requiredpattern-object")
79
+ description: descriptionPrefixesSuffixes("requiredPatterns")
78
80
  },
79
81
  requiredSuffixes: {
80
82
  ...ARRAY_DEFAULT_OPTIONS,
81
- description: descriptionPrefixesSuffixes("requiredPattern", "requiredpattern-object")
83
+ description: descriptionPrefixesSuffixes("requiredPatterns")
82
84
  },
83
85
  ignorePattern: {
84
86
  type: "string",
@@ -270,30 +272,6 @@ const rule = {
270
272
  }
271
273
  `
272
274
  )
273
- },
274
- {
275
- title: "Correct (Relay fragment convention `<module_name>_<property_name>`)",
276
- usage: [
277
- {
278
- FragmentDefinition: {
279
- style: "PascalCase",
280
- requiredPattern: /_(?<camelCase>.+?)$/
281
- }
282
- }
283
- ],
284
- code: (
285
- /* GraphQL */
286
- `
287
- # schema
288
- type User {
289
- # ...
290
- }
291
- # operations
292
- fragment UserFields_data on User {
293
- # ...
294
- }
295
- `
296
- )
297
275
  }
298
276
  ],
299
277
  configOptions: {
@@ -388,7 +366,7 @@ const rule = {
388
366
  requiredPrefixes,
389
367
  requiredSuffixes,
390
368
  forbiddenPatterns,
391
- requiredPattern
369
+ requiredPatterns
392
370
  } = normalisePropertyOption(selector);
393
371
  const nodeName = node.value;
394
372
  const error = getError();
@@ -407,9 +385,7 @@ const rule = {
407
385
  );
408
386
  }
409
387
  function getError() {
410
- let name = nodeName;
411
- if (allowLeadingUnderscore) name = name.replace(/^_+/, "");
412
- if (allowTrailingUnderscore) name = name.replace(/_+$/, "");
388
+ const name = nodeName.replace(/(^_+)|(_+$)/g, "");
413
389
  if (ignorePattern && new RegExp(ignorePattern, "u").test(name)) {
414
390
  if ("name" in n) {
415
391
  ignoredNodes.add(n.name);
@@ -428,38 +404,6 @@ const rule = {
428
404
  renameToNames: [name + suffix]
429
405
  };
430
406
  }
431
- if (requiredPattern) {
432
- if (requiredPattern.source.includes("(?<")) {
433
- try {
434
- name = name.replace(requiredPattern, (originalString, ...args) => {
435
- const groups = args.at(-1);
436
- for (const [styleName, value] of Object.entries(groups)) {
437
- if (!(styleName in StyleToRegex)) {
438
- throw new Error("Invalid case style in `requiredPatterns` option");
439
- }
440
- if (value === convertCase(styleName, value)) {
441
- return "";
442
- }
443
- throw new Error(`contain the required pattern: ${requiredPattern}`);
444
- }
445
- return originalString;
446
- });
447
- if (name === nodeName) {
448
- throw new Error(`contain the required pattern: ${requiredPattern}`);
449
- }
450
- } catch (error2) {
451
- return {
452
- errorMessage: error2.message,
453
- renameToNames: []
454
- };
455
- }
456
- } else if (!requiredPattern.test(name)) {
457
- return {
458
- errorMessage: `contain the required pattern: ${requiredPattern}`,
459
- renameToNames: []
460
- };
461
- }
462
- }
463
407
  const forbidden = forbiddenPatterns?.find((pattern) => pattern.test(name));
464
408
  if (forbidden) {
465
409
  return {
@@ -467,6 +411,12 @@ const rule = {
467
411
  renameToNames: [name.replace(forbidden, "")]
468
412
  };
469
413
  }
414
+ if (requiredPatterns && !requiredPatterns.some((pattern) => pattern.test(name))) {
415
+ return {
416
+ errorMessage: `contain the required pattern: ${englishJoinWords(requiredPatterns.map((re) => re.source))}`,
417
+ renameToNames: []
418
+ };
419
+ }
470
420
  const forbiddenPrefix = forbiddenPrefixes?.find((prefix2) => name.startsWith(prefix2));
471
421
  if (forbiddenPrefix) {
472
422
  return {
@@ -1,91 +1,25 @@
1
- import { FromSchema } from 'json-schema-to-ts';
1
+ import { Kind } from 'graphql';
2
2
  import { GraphQLESLintRule } from '../../types.js';
3
3
  import 'eslint';
4
4
  import 'estree';
5
- import 'graphql';
6
5
  import 'graphql-config';
6
+ import 'json-schema-to-ts';
7
7
  import '../../estree-converter/types.js';
8
8
  import '../../siblings.js';
9
9
  import '@graphql-tools/utils';
10
10
 
11
11
  declare const RULE_ID = "require-description";
12
- declare const schema: {
13
- readonly type: "array";
14
- readonly minItems: 1;
15
- readonly maxItems: 1;
16
- readonly items: {
17
- readonly type: "object";
18
- readonly additionalProperties: false;
19
- readonly minProperties: 1;
20
- readonly properties: {
21
- readonly OperationDefinition: {
22
- type: "boolean";
23
- description: string;
24
- };
25
- readonly ScalarTypeDefinition: {
26
- type: "boolean";
27
- description: string;
28
- };
29
- readonly ObjectTypeDefinition: {
30
- type: "boolean";
31
- description: string;
32
- };
33
- readonly FieldDefinition: {
34
- type: "boolean";
35
- description: string;
36
- };
37
- readonly InputValueDefinition: {
38
- type: "boolean";
39
- description: string;
40
- };
41
- readonly InterfaceTypeDefinition: {
42
- type: "boolean";
43
- description: string;
44
- };
45
- readonly UnionTypeDefinition: {
46
- type: "boolean";
47
- description: string;
48
- };
49
- readonly EnumTypeDefinition: {
50
- type: "boolean";
51
- description: string;
52
- };
53
- readonly EnumValueDefinition: {
54
- type: "boolean";
55
- description: string;
56
- };
57
- readonly InputObjectTypeDefinition: {
58
- type: "boolean";
59
- description: string;
60
- };
61
- readonly DirectiveDefinition: {
62
- type: "boolean";
63
- description: string;
64
- };
65
- readonly types: {
66
- readonly type: "boolean";
67
- readonly enum: readonly [true];
68
- readonly description: `Includes:
69
- ${string}`;
70
- };
71
- readonly rootField: {
72
- readonly type: "boolean";
73
- readonly enum: readonly [true];
74
- readonly description: "Definitions within `Query`, `Mutation`, and `Subscription` root types.";
75
- };
76
- readonly ignoredSelectors: {
77
- readonly description: string;
78
- readonly type: "array";
79
- readonly uniqueItems: true;
80
- readonly minItems: 1;
81
- readonly items: {
82
- readonly type: "string";
83
- };
84
- };
85
- };
86
- };
87
- };
88
- type RuleOptions = FromSchema<typeof schema>;
12
+ declare const ALLOWED_KINDS: readonly [Kind.OBJECT_TYPE_DEFINITION, Kind.INTERFACE_TYPE_DEFINITION, Kind.ENUM_TYPE_DEFINITION, Kind.SCALAR_TYPE_DEFINITION, Kind.INPUT_OBJECT_TYPE_DEFINITION, Kind.UNION_TYPE_DEFINITION, Kind.DIRECTIVE_DEFINITION, Kind.FIELD_DEFINITION, Kind.INPUT_VALUE_DEFINITION, Kind.ENUM_VALUE_DEFINITION, Kind.OPERATION_DEFINITION];
13
+ type AllowedKind = (typeof ALLOWED_KINDS)[number];
14
+ type RuleOptions = [
15
+ {
16
+ [key in AllowedKind]?: boolean;
17
+ } & {
18
+ types?: true;
19
+ rootField?: true;
20
+ ignoredSelectors?: string[];
21
+ }
22
+ ];
89
23
  declare const rule: GraphQLESLintRule<RuleOptions>;
90
24
 
91
25
  export { RULE_ID, type RuleOptions, rule };
@@ -17,22 +17,6 @@ const ALLOWED_KINDS = [
17
17
  Kind.ENUM_VALUE_DEFINITION,
18
18
  Kind.OPERATION_DEFINITION
19
19
  ];
20
- const entries = /* @__PURE__ */ Object.create(null);
21
- for (const kind of [...ALLOWED_KINDS].sort()) {
22
- let description = `> [!NOTE]
23
- >
24
- > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
25
- if (kind === Kind.OPERATION_DEFINITION) {
26
- description += [
27
- "",
28
- "",
29
- "> [!WARNING]",
30
- ">",
31
- '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'
32
- ].join("\n");
33
- }
34
- entries[kind] = { type: "boolean", description };
35
- }
36
20
  const schema = {
37
21
  type: "array",
38
22
  minItems: 1,
@@ -57,7 +41,23 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
57
41
  ...ARRAY_DEFAULT_OPTIONS,
58
42
  description: ["Ignore specific selectors", eslintSelectorsTip].join("\n")
59
43
  },
60
- ...entries
44
+ ...Object.fromEntries(
45
+ [...ALLOWED_KINDS].sort().map((kind) => {
46
+ let description = `> [!NOTE]
47
+ >
48
+ > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
49
+ if (kind === Kind.OPERATION_DEFINITION) {
50
+ description += [
51
+ "",
52
+ "",
53
+ "> [!WARNING]",
54
+ ">",
55
+ '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'
56
+ ].join("\n");
57
+ }
58
+ return [kind, { type: "boolean", description }];
59
+ })
60
+ )
61
61
  }
62
62
  }
63
63
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561",
3
+ "version": "4.3.1-alpha-20241209185034-de2d7397da8c26620a8930dd12b6dff42e43f537",
4
4
  "type": "module",
5
5
  "description": "GraphQL plugin for ESLint",
6
6
  "repository": "https://github.com/dimaMachina/graphql-eslint",
@@ -20,6 +20,16 @@
20
20
  "types": "./esm/index.d.ts",
21
21
  "default": "./esm/index.js"
22
22
  }
23
+ },
24
+ "./*": {
25
+ "require": {
26
+ "types": "./cjs/*.d.cts",
27
+ "default": "./cjs/*.js"
28
+ },
29
+ "import": {
30
+ "types": "./esm/*.d.ts",
31
+ "default": "./esm/*.js"
32
+ }
23
33
  }
24
34
  },
25
35
  "types": "esm/index.d.ts",