@graphql-eslint/eslint-plugin 2.3.0 → 2.3.1

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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/docs/README.md +1 -1
  3. package/docs/custom-rules.md +2 -2
  4. package/docs/rules/alphabetize.md +6 -1
  5. package/docs/rules/avoid-duplicate-fields.md +6 -1
  6. package/docs/rules/avoid-operation-name-prefix.md +5 -1
  7. package/docs/rules/avoid-scalar-result-type-on-mutation.md +6 -1
  8. package/docs/rules/avoid-typename-prefix.md +6 -1
  9. package/docs/rules/description-style.md +6 -1
  10. package/docs/rules/executable-definitions.md +6 -1
  11. package/docs/rules/fields-on-correct-type.md +6 -1
  12. package/docs/rules/fragments-on-composite-type.md +6 -1
  13. package/docs/rules/input-name.md +6 -1
  14. package/docs/rules/known-argument-names.md +6 -1
  15. package/docs/rules/known-directives.md +6 -1
  16. package/docs/rules/known-fragment-names.md +6 -1
  17. package/docs/rules/known-type-names.md +6 -1
  18. package/docs/rules/lone-anonymous-operation.md +6 -1
  19. package/docs/rules/lone-schema-definition.md +6 -1
  20. package/docs/rules/match-document-filename.md +6 -1
  21. package/docs/rules/naming-convention.md +6 -1
  22. package/docs/rules/no-anonymous-operations.md +6 -1
  23. package/docs/rules/no-case-insensitive-enum-values-duplicates.md +5 -1
  24. package/docs/rules/no-deprecated.md +6 -1
  25. package/docs/rules/no-fragment-cycles.md +6 -1
  26. package/docs/rules/no-hashtag-description.md +6 -1
  27. package/docs/rules/no-operation-name-suffix.md +5 -1
  28. package/docs/rules/no-undefined-variables.md +6 -1
  29. package/docs/rules/no-unreachable-types.md +6 -1
  30. package/docs/rules/no-unused-fields.md +6 -1
  31. package/docs/rules/no-unused-fragments.md +6 -1
  32. package/docs/rules/no-unused-variables.md +6 -1
  33. package/docs/rules/one-field-subscriptions.md +6 -1
  34. package/docs/rules/overlapping-fields-can-be-merged.md +6 -1
  35. package/docs/rules/possible-fragment-spread.md +6 -1
  36. package/docs/rules/possible-type-extension.md +6 -1
  37. package/docs/rules/provided-required-arguments.md +6 -1
  38. package/docs/rules/require-deprecation-date.md +6 -1
  39. package/docs/rules/require-deprecation-reason.md +6 -1
  40. package/docs/rules/require-description.md +6 -1
  41. package/docs/rules/require-field-of-type-query-in-mutation-result.md +6 -1
  42. package/docs/rules/require-id-when-available.md +6 -1
  43. package/docs/rules/scalar-leafs.md +6 -1
  44. package/docs/rules/selection-set-depth.md +6 -1
  45. package/docs/rules/strict-id-in-types.md +6 -1
  46. package/docs/rules/unique-argument-names.md +6 -1
  47. package/docs/rules/unique-directive-names-per-location.md +6 -1
  48. package/docs/rules/unique-directive-names.md +6 -1
  49. package/docs/rules/unique-enum-value-names.md +6 -1
  50. package/docs/rules/unique-field-definition-names.md +6 -1
  51. package/docs/rules/unique-fragment-name.md +6 -1
  52. package/docs/rules/unique-input-field-names.md +6 -1
  53. package/docs/rules/unique-operation-name.md +6 -1
  54. package/docs/rules/unique-operation-types.md +6 -1
  55. package/docs/rules/unique-type-names.md +6 -1
  56. package/docs/rules/unique-variable-names.md +6 -1
  57. package/docs/rules/value-literals-of-correct-type.md +6 -1
  58. package/docs/rules/variables-are-input-types.md +6 -1
  59. package/docs/rules/variables-in-allowed-position.md +6 -1
  60. package/index.js +66 -25
  61. package/index.mjs +66 -25
  62. package/package.json +1 -1
  63. package/types.d.ts +2 -0
@@ -9,4 +9,9 @@
9
9
 
10
10
  A GraphQL input object value is only valid if all supplied fields are uniquely named.
11
11
 
12
- > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueInputFieldNamesRule.ts).
12
+ > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueInputFieldNamesRule.ts).
13
+
14
+ ## Resources
15
+
16
+ - [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueInputFieldNamesRule.ts)
17
+ - [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueInputFieldNamesRule-test.ts)
@@ -47,4 +47,9 @@ query me {
47
47
  id
48
48
  }
49
49
  }
50
- ```
50
+ ```
51
+
52
+ ## Resources
53
+
54
+ - [Rule source](../../packages/plugin/src/rules/unique-operation-name.ts)
55
+ - [Test source](../../packages/plugin/tests/unique-operation-name.spec.ts)
@@ -9,4 +9,9 @@
9
9
 
10
10
  A GraphQL document is only valid if it has only one type per operation.
11
11
 
12
- > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueOperationTypesRule.ts).
12
+ > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueOperationTypesRule.ts).
13
+
14
+ ## Resources
15
+
16
+ - [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueOperationTypesRule.ts)
17
+ - [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueOperationTypesRule-test.ts)
@@ -9,4 +9,9 @@
9
9
 
10
10
  A GraphQL document is only valid if all defined types have unique names.
11
11
 
12
- > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueTypeNamesRule.ts).
12
+ > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueTypeNamesRule.ts).
13
+
14
+ ## Resources
15
+
16
+ - [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueTypeNamesRule.ts)
17
+ - [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueTypeNamesRule-test.ts)
@@ -9,4 +9,9 @@
9
9
 
10
10
  A GraphQL operation is only valid if all its variables are uniquely named.
11
11
 
12
- > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueVariableNamesRule.ts).
12
+ > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueVariableNamesRule.ts).
13
+
14
+ ## Resources
15
+
16
+ - [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueVariableNamesRule.ts)
17
+ - [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueVariableNamesRule-test.ts)
@@ -9,4 +9,9 @@
9
9
 
10
10
  A GraphQL document is only valid if all value literals are of the type expected at their position.
11
11
 
12
- > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ValuesOfCorrectTypeRule.ts).
12
+ > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ValuesOfCorrectTypeRule.ts).
13
+
14
+ ## Resources
15
+
16
+ - [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ValuesOfCorrectTypeRule.ts)
17
+ - [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts)
@@ -9,4 +9,9 @@
9
9
 
10
10
  A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).
11
11
 
12
- > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/VariablesAreInputTypesRule.ts).
12
+ > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/VariablesAreInputTypesRule.ts).
13
+
14
+ ## Resources
15
+
16
+ - [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/VariablesAreInputTypesRule.ts)
17
+ - [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/VariablesAreInputTypesRule-test.ts)
@@ -9,4 +9,9 @@
9
9
 
10
10
  Variables passed to field arguments conform to type.
11
11
 
12
- > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/VariablesInAllowedPositionRule.ts).
12
+ > This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/VariablesInAllowedPositionRule.ts).
13
+
14
+ ## Resources
15
+
16
+ - [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/VariablesInAllowedPositionRule.ts)
17
+ - [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts)
package/index.js CHANGED
@@ -292,6 +292,7 @@ const validationToRule = (name, ruleName, docs, getDocumentNode) => {
292
292
  meta: {
293
293
  docs: {
294
294
  ...docs,
295
+ graphQLJSRuleName: ruleName,
295
296
  category: 'Validation',
296
297
  recommended: true,
297
298
  requiresSchema,
@@ -656,10 +657,7 @@ const rule = {
656
657
  line: start.line,
657
658
  column: start.column - (isVariableNode ? 2 : 1),
658
659
  },
659
- end: {
660
- line: end.line,
661
- column: end.column,
662
- },
660
+ end,
663
661
  },
664
662
  messageId: ALPHABETIZE,
665
663
  data: isVariableNode
@@ -790,6 +788,7 @@ const rule$1 = {
790
788
  messages: {
791
789
  [AVOID_DUPLICATE_FIELDS]: `{{ type }} "{{ fieldName }}" defined multiple times.`,
792
790
  },
791
+ schema: [],
793
792
  },
794
793
  create(context) {
795
794
  return {
@@ -909,15 +908,16 @@ const rule$2 = {
909
908
  const testKeyword = caseSensitive ? keyword : keyword.toLowerCase();
910
909
  const testName = caseSensitive ? node.name.value : node.name.value.toLowerCase();
911
910
  if (testName.startsWith(testKeyword)) {
911
+ const { start } = node.name.loc;
912
912
  context.report({
913
913
  loc: {
914
914
  start: {
915
- line: node.name.loc.start.line,
916
- column: node.name.loc.start.column - 1,
915
+ line: start.line,
916
+ column: start.column - 1,
917
917
  },
918
918
  end: {
919
- line: node.name.loc.start.line,
920
- column: node.name.loc.start.column + testKeyword.length - 1,
919
+ line: start.line,
920
+ column: start.column - 1 + testKeyword.length,
921
921
  },
922
922
  },
923
923
  data: {
@@ -960,6 +960,7 @@ const rule$3 = {
960
960
  },
961
961
  ],
962
962
  },
963
+ schema: [],
963
964
  },
964
965
  create(context) {
965
966
  const schema = requireGraphQLSchemaFromContext('avoid-scalar-result-type-on-mutation', context);
@@ -1015,22 +1016,33 @@ const rule$4 = {
1015
1016
  messages: {
1016
1017
  [AVOID_TYPENAME_PREFIX]: `Field "{{ fieldName }}" starts with the name of the parent type "{{ typeName }}"`,
1017
1018
  },
1019
+ schema: [],
1018
1020
  },
1019
1021
  create(context) {
1020
1022
  return {
1021
1023
  'ObjectTypeDefinition, ObjectTypeExtension, InterfaceTypeDefinition, InterfaceTypeExtension'(node) {
1022
1024
  const typeName = node.name.value;
1023
- const lowerTypeName = (typeName || '').toLowerCase();
1025
+ const lowerTypeName = typeName.toLowerCase();
1024
1026
  for (const field of node.fields) {
1025
- const fieldName = field.name.value || '';
1026
- if (fieldName && lowerTypeName && fieldName.toLowerCase().startsWith(lowerTypeName)) {
1027
+ const fieldName = field.name.value;
1028
+ if (fieldName.toLowerCase().startsWith(lowerTypeName)) {
1029
+ const { start } = field.loc;
1027
1030
  context.report({
1028
- node: field.name,
1029
1031
  data: {
1030
1032
  fieldName,
1031
1033
  typeName,
1032
1034
  },
1033
1035
  messageId: AVOID_TYPENAME_PREFIX,
1036
+ loc: {
1037
+ start: {
1038
+ line: start.line,
1039
+ column: start.column - 1,
1040
+ },
1041
+ end: {
1042
+ line: start.line,
1043
+ column: start.column - 1 + lowerTypeName.length,
1044
+ },
1045
+ },
1034
1046
  });
1035
1047
  }
1036
1048
  }
@@ -1728,20 +1740,24 @@ const rule$9 = {
1728
1740
  messages: {
1729
1741
  [NO_ANONYMOUS_OPERATIONS]: `Anonymous GraphQL operations are forbidden. Please make sure to name your {{ operation }}!`,
1730
1742
  },
1743
+ schema: [],
1731
1744
  },
1732
1745
  create(context) {
1733
1746
  return {
1734
1747
  OperationDefinition(node) {
1735
- if (node && (!node.name || node.name.value === '')) {
1748
+ var _a;
1749
+ const isAnonymous = (((_a = node.name) === null || _a === void 0 ? void 0 : _a.value) || '').length === 0;
1750
+ if (isAnonymous) {
1751
+ const { start } = node.loc;
1736
1752
  context.report({
1737
1753
  loc: {
1738
1754
  start: {
1739
- column: node.loc.start.column - 1,
1740
- line: node.loc.start.line,
1755
+ column: start.column - 1,
1756
+ line: start.line,
1741
1757
  },
1742
1758
  end: {
1743
- column: node.loc.start.column + node.operation.length,
1744
- line: node.loc.start.line,
1759
+ column: start.column - 1 + node.operation.length,
1760
+ line: start.line,
1745
1761
  },
1746
1762
  },
1747
1763
  data: {
@@ -1791,6 +1807,7 @@ const rule$a = {
1791
1807
  messages: {
1792
1808
  [ERROR_MESSAGE_ID]: `Case-insensitive enum values duplicates are not allowed! Found: "{{ found }}"`,
1793
1809
  },
1810
+ schema: [],
1794
1811
  },
1795
1812
  create(context) {
1796
1813
  return {
@@ -1885,6 +1902,7 @@ const rule$b = {
1885
1902
  messages: {
1886
1903
  [NO_DEPRECATED]: `This {{ type }} is marked as deprecated in your GraphQL schema {{ reason }}`,
1887
1904
  },
1905
+ schema: [],
1888
1906
  },
1889
1907
  create(context) {
1890
1908
  return {
@@ -1971,6 +1989,7 @@ const rule$c = {
1971
1989
  ],
1972
1990
  },
1973
1991
  type: 'suggestion',
1992
+ schema: [],
1974
1993
  },
1975
1994
  create(context) {
1976
1995
  return {
@@ -2031,15 +2050,28 @@ const rule$d = {
2031
2050
  messages: {
2032
2051
  [NO_OPERATION_NAME_SUFFIX]: `Unnecessary "{{ invalidSuffix }}" suffix in your operation name!`,
2033
2052
  },
2053
+ schema: [],
2034
2054
  },
2035
2055
  create(context) {
2036
2056
  return {
2037
2057
  'OperationDefinition, FragmentDefinition'(node) {
2038
- if (node && node.name && node.name.value !== '') {
2039
- const invalidSuffix = (node.type === 'OperationDefinition' ? node.operation : 'fragment').toLowerCase();
2040
- if (node.name.value.toLowerCase().endsWith(invalidSuffix)) {
2058
+ var _a;
2059
+ const name = ((_a = node.name) === null || _a === void 0 ? void 0 : _a.value) || '';
2060
+ if (name.length > 0) {
2061
+ const invalidSuffix = 'operation' in node ? node.operation : 'fragment';
2062
+ if (name.toLowerCase().endsWith(invalidSuffix)) {
2063
+ const { start, end } = node.name.loc;
2041
2064
  context.report({
2042
- node: node.name,
2065
+ loc: {
2066
+ start: {
2067
+ column: start.column - 1 + name.length - invalidSuffix.length,
2068
+ line: start.line,
2069
+ },
2070
+ end: {
2071
+ column: end.column - 1 + name.length,
2072
+ line: end.line,
2073
+ },
2074
+ },
2043
2075
  data: {
2044
2076
  invalidSuffix,
2045
2077
  },
@@ -2096,6 +2128,7 @@ const rule$e = {
2096
2128
  },
2097
2129
  fixable: 'code',
2098
2130
  type: 'suggestion',
2131
+ schema: [],
2099
2132
  },
2100
2133
  create(context) {
2101
2134
  const reachableTypes = requireReachableTypesFromContext(RULE_NAME, context);
@@ -2187,6 +2220,7 @@ const rule$f = {
2187
2220
  },
2188
2221
  fixable: 'code',
2189
2222
  type: 'suggestion',
2223
+ schema: [],
2190
2224
  },
2191
2225
  create(context) {
2192
2226
  const usedFields = requireUsedFieldsFromContext(RULE_NAME$1, context);
@@ -2452,6 +2486,7 @@ const rule$h = {
2452
2486
  ],
2453
2487
  },
2454
2488
  type: 'suggestion',
2489
+ schema: [],
2455
2490
  },
2456
2491
  create(context) {
2457
2492
  return {
@@ -2488,15 +2523,18 @@ const DESCRIBABLE_NODES = [
2488
2523
  function verifyRule(context, node) {
2489
2524
  if (node) {
2490
2525
  if (!node.description || !node.description.value || node.description.value.trim().length === 0) {
2526
+ const { start, end } = ('name' in node ? node.name : node).loc;
2491
2527
  context.report({
2492
2528
  loc: {
2493
2529
  start: {
2494
- line: node.loc.start.line,
2495
- column: node.loc.start.column - 1,
2530
+ line: start.line,
2531
+ column: start.column - 1,
2496
2532
  },
2497
2533
  end: {
2498
- line: node.loc.end.line,
2499
- column: node.loc.end.column,
2534
+ line: end.line,
2535
+ column:
2536
+ // node.name don't exist on SchemaDefinition
2537
+ 'name' in node ? end.column - 1 + node.name.value.length : end.column,
2500
2538
  },
2501
2539
  },
2502
2540
  messageId: REQUIRE_DESCRIPTION_ERROR,
@@ -2610,6 +2648,7 @@ const rule$j = {
2610
2648
  },
2611
2649
  ],
2612
2650
  },
2651
+ schema: [],
2613
2652
  },
2614
2653
  create(context) {
2615
2654
  const schema = requireGraphQLSchemaFromContext(RULE_NAME$2, context);
@@ -3229,6 +3268,7 @@ const rule$n = {
3229
3268
  messages: {
3230
3269
  [UNIQUE_FRAGMENT_NAME]: 'Fragment named "{{ documentName }}" already defined in:\n{{ summary }}',
3231
3270
  },
3271
+ schema: [],
3232
3272
  },
3233
3273
  create(context) {
3234
3274
  return {
@@ -3291,6 +3331,7 @@ const rule$o = {
3291
3331
  messages: {
3292
3332
  [UNIQUE_OPERATION_NAME]: 'Operation named "{{ documentName }}" already defined in:\n{{ summary }}',
3293
3333
  },
3334
+ schema: [],
3294
3335
  },
3295
3336
  create(context) {
3296
3337
  return {
package/index.mjs CHANGED
@@ -286,6 +286,7 @@ const validationToRule = (name, ruleName, docs, getDocumentNode) => {
286
286
  meta: {
287
287
  docs: {
288
288
  ...docs,
289
+ graphQLJSRuleName: ruleName,
289
290
  category: 'Validation',
290
291
  recommended: true,
291
292
  requiresSchema,
@@ -650,10 +651,7 @@ const rule = {
650
651
  line: start.line,
651
652
  column: start.column - (isVariableNode ? 2 : 1),
652
653
  },
653
- end: {
654
- line: end.line,
655
- column: end.column,
656
- },
654
+ end,
657
655
  },
658
656
  messageId: ALPHABETIZE,
659
657
  data: isVariableNode
@@ -784,6 +782,7 @@ const rule$1 = {
784
782
  messages: {
785
783
  [AVOID_DUPLICATE_FIELDS]: `{{ type }} "{{ fieldName }}" defined multiple times.`,
786
784
  },
785
+ schema: [],
787
786
  },
788
787
  create(context) {
789
788
  return {
@@ -903,15 +902,16 @@ const rule$2 = {
903
902
  const testKeyword = caseSensitive ? keyword : keyword.toLowerCase();
904
903
  const testName = caseSensitive ? node.name.value : node.name.value.toLowerCase();
905
904
  if (testName.startsWith(testKeyword)) {
905
+ const { start } = node.name.loc;
906
906
  context.report({
907
907
  loc: {
908
908
  start: {
909
- line: node.name.loc.start.line,
910
- column: node.name.loc.start.column - 1,
909
+ line: start.line,
910
+ column: start.column - 1,
911
911
  },
912
912
  end: {
913
- line: node.name.loc.start.line,
914
- column: node.name.loc.start.column + testKeyword.length - 1,
913
+ line: start.line,
914
+ column: start.column - 1 + testKeyword.length,
915
915
  },
916
916
  },
917
917
  data: {
@@ -954,6 +954,7 @@ const rule$3 = {
954
954
  },
955
955
  ],
956
956
  },
957
+ schema: [],
957
958
  },
958
959
  create(context) {
959
960
  const schema = requireGraphQLSchemaFromContext('avoid-scalar-result-type-on-mutation', context);
@@ -1009,22 +1010,33 @@ const rule$4 = {
1009
1010
  messages: {
1010
1011
  [AVOID_TYPENAME_PREFIX]: `Field "{{ fieldName }}" starts with the name of the parent type "{{ typeName }}"`,
1011
1012
  },
1013
+ schema: [],
1012
1014
  },
1013
1015
  create(context) {
1014
1016
  return {
1015
1017
  'ObjectTypeDefinition, ObjectTypeExtension, InterfaceTypeDefinition, InterfaceTypeExtension'(node) {
1016
1018
  const typeName = node.name.value;
1017
- const lowerTypeName = (typeName || '').toLowerCase();
1019
+ const lowerTypeName = typeName.toLowerCase();
1018
1020
  for (const field of node.fields) {
1019
- const fieldName = field.name.value || '';
1020
- if (fieldName && lowerTypeName && fieldName.toLowerCase().startsWith(lowerTypeName)) {
1021
+ const fieldName = field.name.value;
1022
+ if (fieldName.toLowerCase().startsWith(lowerTypeName)) {
1023
+ const { start } = field.loc;
1021
1024
  context.report({
1022
- node: field.name,
1023
1025
  data: {
1024
1026
  fieldName,
1025
1027
  typeName,
1026
1028
  },
1027
1029
  messageId: AVOID_TYPENAME_PREFIX,
1030
+ loc: {
1031
+ start: {
1032
+ line: start.line,
1033
+ column: start.column - 1,
1034
+ },
1035
+ end: {
1036
+ line: start.line,
1037
+ column: start.column - 1 + lowerTypeName.length,
1038
+ },
1039
+ },
1028
1040
  });
1029
1041
  }
1030
1042
  }
@@ -1722,20 +1734,24 @@ const rule$9 = {
1722
1734
  messages: {
1723
1735
  [NO_ANONYMOUS_OPERATIONS]: `Anonymous GraphQL operations are forbidden. Please make sure to name your {{ operation }}!`,
1724
1736
  },
1737
+ schema: [],
1725
1738
  },
1726
1739
  create(context) {
1727
1740
  return {
1728
1741
  OperationDefinition(node) {
1729
- if (node && (!node.name || node.name.value === '')) {
1742
+ var _a;
1743
+ const isAnonymous = (((_a = node.name) === null || _a === void 0 ? void 0 : _a.value) || '').length === 0;
1744
+ if (isAnonymous) {
1745
+ const { start } = node.loc;
1730
1746
  context.report({
1731
1747
  loc: {
1732
1748
  start: {
1733
- column: node.loc.start.column - 1,
1734
- line: node.loc.start.line,
1749
+ column: start.column - 1,
1750
+ line: start.line,
1735
1751
  },
1736
1752
  end: {
1737
- column: node.loc.start.column + node.operation.length,
1738
- line: node.loc.start.line,
1753
+ column: start.column - 1 + node.operation.length,
1754
+ line: start.line,
1739
1755
  },
1740
1756
  },
1741
1757
  data: {
@@ -1785,6 +1801,7 @@ const rule$a = {
1785
1801
  messages: {
1786
1802
  [ERROR_MESSAGE_ID]: `Case-insensitive enum values duplicates are not allowed! Found: "{{ found }}"`,
1787
1803
  },
1804
+ schema: [],
1788
1805
  },
1789
1806
  create(context) {
1790
1807
  return {
@@ -1879,6 +1896,7 @@ const rule$b = {
1879
1896
  messages: {
1880
1897
  [NO_DEPRECATED]: `This {{ type }} is marked as deprecated in your GraphQL schema {{ reason }}`,
1881
1898
  },
1899
+ schema: [],
1882
1900
  },
1883
1901
  create(context) {
1884
1902
  return {
@@ -1965,6 +1983,7 @@ const rule$c = {
1965
1983
  ],
1966
1984
  },
1967
1985
  type: 'suggestion',
1986
+ schema: [],
1968
1987
  },
1969
1988
  create(context) {
1970
1989
  return {
@@ -2025,15 +2044,28 @@ const rule$d = {
2025
2044
  messages: {
2026
2045
  [NO_OPERATION_NAME_SUFFIX]: `Unnecessary "{{ invalidSuffix }}" suffix in your operation name!`,
2027
2046
  },
2047
+ schema: [],
2028
2048
  },
2029
2049
  create(context) {
2030
2050
  return {
2031
2051
  'OperationDefinition, FragmentDefinition'(node) {
2032
- if (node && node.name && node.name.value !== '') {
2033
- const invalidSuffix = (node.type === 'OperationDefinition' ? node.operation : 'fragment').toLowerCase();
2034
- if (node.name.value.toLowerCase().endsWith(invalidSuffix)) {
2052
+ var _a;
2053
+ const name = ((_a = node.name) === null || _a === void 0 ? void 0 : _a.value) || '';
2054
+ if (name.length > 0) {
2055
+ const invalidSuffix = 'operation' in node ? node.operation : 'fragment';
2056
+ if (name.toLowerCase().endsWith(invalidSuffix)) {
2057
+ const { start, end } = node.name.loc;
2035
2058
  context.report({
2036
- node: node.name,
2059
+ loc: {
2060
+ start: {
2061
+ column: start.column - 1 + name.length - invalidSuffix.length,
2062
+ line: start.line,
2063
+ },
2064
+ end: {
2065
+ column: end.column - 1 + name.length,
2066
+ line: end.line,
2067
+ },
2068
+ },
2037
2069
  data: {
2038
2070
  invalidSuffix,
2039
2071
  },
@@ -2090,6 +2122,7 @@ const rule$e = {
2090
2122
  },
2091
2123
  fixable: 'code',
2092
2124
  type: 'suggestion',
2125
+ schema: [],
2093
2126
  },
2094
2127
  create(context) {
2095
2128
  const reachableTypes = requireReachableTypesFromContext(RULE_NAME, context);
@@ -2181,6 +2214,7 @@ const rule$f = {
2181
2214
  },
2182
2215
  fixable: 'code',
2183
2216
  type: 'suggestion',
2217
+ schema: [],
2184
2218
  },
2185
2219
  create(context) {
2186
2220
  const usedFields = requireUsedFieldsFromContext(RULE_NAME$1, context);
@@ -2446,6 +2480,7 @@ const rule$h = {
2446
2480
  ],
2447
2481
  },
2448
2482
  type: 'suggestion',
2483
+ schema: [],
2449
2484
  },
2450
2485
  create(context) {
2451
2486
  return {
@@ -2482,15 +2517,18 @@ const DESCRIBABLE_NODES = [
2482
2517
  function verifyRule(context, node) {
2483
2518
  if (node) {
2484
2519
  if (!node.description || !node.description.value || node.description.value.trim().length === 0) {
2520
+ const { start, end } = ('name' in node ? node.name : node).loc;
2485
2521
  context.report({
2486
2522
  loc: {
2487
2523
  start: {
2488
- line: node.loc.start.line,
2489
- column: node.loc.start.column - 1,
2524
+ line: start.line,
2525
+ column: start.column - 1,
2490
2526
  },
2491
2527
  end: {
2492
- line: node.loc.end.line,
2493
- column: node.loc.end.column,
2528
+ line: end.line,
2529
+ column:
2530
+ // node.name don't exist on SchemaDefinition
2531
+ 'name' in node ? end.column - 1 + node.name.value.length : end.column,
2494
2532
  },
2495
2533
  },
2496
2534
  messageId: REQUIRE_DESCRIPTION_ERROR,
@@ -2604,6 +2642,7 @@ const rule$j = {
2604
2642
  },
2605
2643
  ],
2606
2644
  },
2645
+ schema: [],
2607
2646
  },
2608
2647
  create(context) {
2609
2648
  const schema = requireGraphQLSchemaFromContext(RULE_NAME$2, context);
@@ -3223,6 +3262,7 @@ const rule$n = {
3223
3262
  messages: {
3224
3263
  [UNIQUE_FRAGMENT_NAME]: 'Fragment named "{{ documentName }}" already defined in:\n{{ summary }}',
3225
3264
  },
3265
+ schema: [],
3226
3266
  },
3227
3267
  create(context) {
3228
3268
  return {
@@ -3285,6 +3325,7 @@ const rule$o = {
3285
3325
  messages: {
3286
3326
  [UNIQUE_OPERATION_NAME]: 'Operation named "{{ documentName }}" already defined in:\n{{ summary }}',
3287
3327
  },
3328
+ schema: [],
3288
3329
  },
3289
3330
  create(context) {
3290
3331
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
package/types.d.ts CHANGED
@@ -56,9 +56,11 @@ export declare type RuleDocsInfo<T> = Rule.RuleMetaData & {
56
56
  usage?: T;
57
57
  }[];
58
58
  optionsForConfig?: T;
59
+ graphQLJSRuleName?: string;
59
60
  };
60
61
  };
61
62
  export declare type GraphQLESLintRule<Options = any[], WithTypeInfo extends boolean = false> = {
62
63
  create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>;
63
64
  meta: Rule.RuleMetaData & RuleDocsInfo<Options>;
64
65
  };
66
+ export declare type ValueOf<T> = T[keyof T];