@graphql-eslint/eslint-plugin 3.0.1-alpha-86a9e78.0 → 3.1.0

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.
@@ -44,7 +44,6 @@ export declare const configs: {
44
44
  '@graphql-eslint/strict-id-in-types': string;
45
45
  '@graphql-eslint/unique-directive-names': string;
46
46
  '@graphql-eslint/unique-directive-names-per-location': string;
47
- '@graphql-eslint/unique-enum-value-names': string;
48
47
  '@graphql-eslint/unique-field-definition-names': string;
49
48
  '@graphql-eslint/unique-operation-types': string;
50
49
  '@graphql-eslint/unique-type-names': string;
@@ -59,10 +58,7 @@ export declare const configs: {
59
58
  arguments: string[];
60
59
  })[];
61
60
  '@graphql-eslint/input-name': string;
62
- '@graphql-eslint/no-root-type': string;
63
61
  '@graphql-eslint/no-scalar-result-type-on-mutation': string;
64
- '@graphql-eslint/no-unused-fields': string;
65
- '@graphql-eslint/possible-type-extension': string;
66
62
  '@graphql-eslint/require-deprecation-date': string;
67
63
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
68
64
  };
@@ -7,10 +7,7 @@ declare const _default: {
7
7
  arguments: string[];
8
8
  })[];
9
9
  '@graphql-eslint/input-name': string;
10
- '@graphql-eslint/no-root-type': string;
11
10
  '@graphql-eslint/no-scalar-result-type-on-mutation': string;
12
- '@graphql-eslint/no-unused-fields': string;
13
- '@graphql-eslint/possible-type-extension': string;
14
11
  '@graphql-eslint/require-deprecation-date': string;
15
12
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
16
13
  };
@@ -39,7 +39,6 @@ declare const _default: {
39
39
  '@graphql-eslint/strict-id-in-types': string;
40
40
  '@graphql-eslint/unique-directive-names': string;
41
41
  '@graphql-eslint/unique-directive-names-per-location': string;
42
- '@graphql-eslint/unique-enum-value-names': string;
43
42
  '@graphql-eslint/unique-field-definition-names': string;
44
43
  '@graphql-eslint/unique-operation-types': string;
45
44
  '@graphql-eslint/unique-type-names': string;
package/docs/README.md CHANGED
@@ -4,66 +4,66 @@ Each rule has emojis denoting:
4
4
 
5
5
  - 🚀 `graphql-eslint` rule
6
6
  - 🔮 `graphql-js` rule
7
- - 🔧 if some problems reported by the rule are automatically fixable by the `--fix` [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) option
8
- - ✅ if it belongs to the `recommended` configuration
9
7
 
10
8
  <!-- 🚨 IMPORTANT! Do not manually modify this table. Run: `yarn generate:docs` -->
11
9
  <!-- prettier-ignore-start -->
12
- Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Description|🚀&nbsp;/&nbsp;🔮|🔧|✅
13
- -|-|:-:|-|-
14
- [alphabetize](rules/alphabetize.md)|Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.|🚀||
15
- [description-style](rules/description-style.md)|Require all comments to follow the same style (either block or inline).|🚀||✅
16
- [executable-definitions](rules/executable-definitions.md)|A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.|🔮||✅
17
- [fields-on-correct-type](rules/fields-on-correct-type.md)|A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.|🔮||✅
18
- [fragments-on-composite-type](rules/fragments-on-composite-type.md)|Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.|🔮||✅
19
- [input-name](rules/input-name.md)|Require mutation argument to be always called "input" and input type to be called Mutation name + "Input".|🚀||
20
- [known-argument-names](rules/known-argument-names.md)|A GraphQL field is only valid if all supplied arguments are defined by that field.|🔮||✅
21
- [known-directives](rules/known-directives.md)|A GraphQL document is only valid if all `@directives` are known by the schema and legally positioned.|🔮||✅
22
- [known-fragment-names](rules/known-fragment-names.md)|A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.|🔮||✅
23
- [known-type-names](rules/known-type-names.md)|A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.|🔮||✅
24
- [lone-anonymous-operation](rules/lone-anonymous-operation.md)|A GraphQL document is only valid if when it contains an anonymous operation (the query short-hand) that it contains only that one operation definition.|🔮||✅
25
- [lone-schema-definition](rules/lone-schema-definition.md)|A GraphQL document is only valid if it contains only one schema definition.|🔮||✅
26
- [match-document-filename](rules/match-document-filename.md)|This rule allows you to enforce that the file name should match the operation name.|🚀||
27
- [naming-convention](rules/naming-convention.md)|Require names to follow specified conventions.|🚀||✅
28
- [no-anonymous-operations](rules/no-anonymous-operations.md)|Require name for your GraphQL operations. This is useful since most GraphQL client libraries are using the operation name for caching purposes.|🚀||✅
29
- [no-case-insensitive-enum-values-duplicates](rules/no-case-insensitive-enum-values-duplicates.md)|Disallow case-insensitive enum values duplicates.|🚀|🔧|✅
30
- [no-deprecated](rules/no-deprecated.md)|Enforce that deprecated fields or enum values are not in use by operations.|🚀||✅
31
- [no-duplicate-fields](rules/no-duplicate-fields.md)|Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field.|🚀||✅
32
- [no-fragment-cycles](rules/no-fragment-cycles.md)|A GraphQL fragment is only valid when it does not have cycles in fragments usage.|🔮||✅
33
- [no-hashtag-description](rules/no-hashtag-description.md)|Requires to use `"""` or `"` for adding a GraphQL description instead of `#`.|🚀||✅
34
- [no-root-type](rules/no-root-type.md)|Disallow using root types `mutation` and/or `subscription`.|🚀||
35
- [no-scalar-result-type-on-mutation](rules/no-scalar-result-type-on-mutation.md)|Avoid scalar result type on mutation type to make sure to return a valid state.|🚀||
36
- [no-typename-prefix](rules/no-typename-prefix.md)|Enforces users to avoid using the type name in a field name while defining your schema.|🚀||✅
37
- [no-undefined-variables](rules/no-undefined-variables.md)|A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.|🔮||✅
38
- [no-unreachable-types](rules/no-unreachable-types.md)|Requires all types to be reachable at some level by root level fields.|🚀|🔧|✅
39
- [no-unused-fields](rules/no-unused-fields.md)|Requires all fields to be used at some level by siblings operations.|🚀|🔧|
40
- [no-unused-fragments](rules/no-unused-fragments.md)|A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.|🔮||✅
41
- [no-unused-variables](rules/no-unused-variables.md)|A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.|🔮||✅
42
- [one-field-subscriptions](rules/one-field-subscriptions.md)|A GraphQL subscription is valid only if it contains a single root field.|🔮||✅
43
- [overlapping-fields-can-be-merged](rules/overlapping-fields-can-be-merged.md)|A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.|🔮||✅
44
- [possible-fragment-spread](rules/possible-fragment-spread.md)|A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.|🔮||✅
45
- [possible-type-extension](rules/possible-type-extension.md)|A type extension is only valid if the type is defined and has the same kind.|🔮||
46
- [provided-required-arguments](rules/provided-required-arguments.md)|A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.|🔮||✅
47
- [require-deprecation-date](rules/require-deprecation-date.md)|Require deletion date on `@deprecated` directive. Suggest removing deprecated things after deprecated date.|🚀||
48
- [require-deprecation-reason](rules/require-deprecation-reason.md)|Require all deprecation directives to specify a reason.|🚀||✅
49
- [require-description](rules/require-description.md)|Enforce descriptions in your type definitions.|🚀||✅
50
- [require-field-of-type-query-in-mutation-result](rules/require-field-of-type-query-in-mutation-result.md)|Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.|🚀||
51
- [require-id-when-available](rules/require-id-when-available.md)|Enforce selecting specific fields when they are available on the GraphQL type.|🚀||✅
52
- [scalar-leafs](rules/scalar-leafs.md)|A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.|🔮||✅
53
- [selection-set-depth](rules/selection-set-depth.md)|Limit the complexity of the GraphQL operations solely by their depth. Based on [graphql-depth-limit](https://github.com/stems/graphql-depth-limit).|🚀||✅
54
- [strict-id-in-types](rules/strict-id-in-types.md)|Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.|🚀||✅
55
- [unique-argument-names](rules/unique-argument-names.md)|A GraphQL field or directive is only valid if all supplied arguments are uniquely named.|🔮||✅
56
- [unique-directive-names](rules/unique-directive-names.md)|A GraphQL document is only valid if all defined directives have unique names.|🔮||✅
57
- [unique-directive-names-per-location](rules/unique-directive-names-per-location.md)|A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.|🔮||✅
58
- [unique-enum-value-names](rules/unique-enum-value-names.md)|A GraphQL enum type is only valid if all its values are uniquely named.|🔮||✅
59
- [unique-field-definition-names](rules/unique-field-definition-names.md)|A GraphQL complex type is only valid if all its fields are uniquely named.|🔮||✅
60
- [unique-fragment-name](rules/unique-fragment-name.md)|Enforce unique fragment names across your project.|🚀||
61
- [unique-input-field-names](rules/unique-input-field-names.md)|A GraphQL input object value is only valid if all supplied fields are uniquely named.|🔮||✅
62
- [unique-operation-name](rules/unique-operation-name.md)|Enforce unique operation names across your project.|🚀||
63
- [unique-operation-types](rules/unique-operation-types.md)|A GraphQL document is only valid if it has only one type per operation.|🔮||✅
64
- [unique-type-names](rules/unique-type-names.md)|A GraphQL document is only valid if all defined types have unique names.|🔮||✅
65
- [unique-variable-names](rules/unique-variable-names.md)|A GraphQL operation is only valid if all its variables are uniquely named.|🔮||✅
66
- [value-literals-of-correct-type](rules/value-literals-of-correct-type.md)|A GraphQL document is only valid if all value literals are of the type expected at their position.|🔮||✅
67
- [variables-are-input-types](rules/variables-are-input-types.md)|A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).|🔮||✅
68
- [variables-in-allowed-position](rules/variables-in-allowed-position.md)|Variables passed to field arguments conform to type.|🔮||✅
10
+ Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Description|&nbsp;&nbsp;&nbsp;&nbsp;Config&nbsp;&nbsp;&nbsp;&nbsp;|🚀&nbsp;/&nbsp;🔮
11
+ -|-|:-:|:-:
12
+ [alphabetize](rules/alphabetize.md)|Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.|![all][]|🚀
13
+ [description-style](rules/description-style.md)|Require all comments to follow the same style (either block or inline).|![recommended][]|🚀
14
+ [executable-definitions](rules/executable-definitions.md)|A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.|![recommended][]|🔮
15
+ [fields-on-correct-type](rules/fields-on-correct-type.md)|A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.|![recommended][]|🔮
16
+ [fragments-on-composite-type](rules/fragments-on-composite-type.md)|Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.|![recommended][]|🔮
17
+ [input-name](rules/input-name.md)|Require mutation argument to be always called "input" and input type to be called Mutation name + "Input".|![all][]|🚀
18
+ [known-argument-names](rules/known-argument-names.md)|A GraphQL field is only valid if all supplied arguments are defined by that field.|![recommended][]|🔮
19
+ [known-directives](rules/known-directives.md)|A GraphQL document is only valid if all `@directives` are known by the schema and legally positioned.|![recommended][]|🔮
20
+ [known-fragment-names](rules/known-fragment-names.md)|A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.|![recommended][]|🔮
21
+ [known-type-names](rules/known-type-names.md)|A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.|![recommended][]|🔮
22
+ [lone-anonymous-operation](rules/lone-anonymous-operation.md)|A GraphQL document is only valid if when it contains an anonymous operation (the query short-hand) that it contains only that one operation definition.|![recommended][]|🔮
23
+ [lone-schema-definition](rules/lone-schema-definition.md)|A GraphQL document is only valid if it contains only one schema definition.|![recommended][]|🔮
24
+ [match-document-filename](rules/match-document-filename.md)|This rule allows you to enforce that the file name should match the operation name.|![all][]|🚀
25
+ [naming-convention](rules/naming-convention.md)|Require names to follow specified conventions.|![recommended][]|🚀
26
+ [no-anonymous-operations](rules/no-anonymous-operations.md)|Require name for your GraphQL operations. This is useful since most GraphQL client libraries are using the operation name for caching purposes.|![recommended][]|🚀
27
+ [no-case-insensitive-enum-values-duplicates](rules/no-case-insensitive-enum-values-duplicates.md)|Disallow case-insensitive enum values duplicates.|![recommended][]|🚀
28
+ [no-deprecated](rules/no-deprecated.md)|Enforce that deprecated fields or enum values are not in use by operations.|![recommended][]|🚀
29
+ [no-duplicate-fields](rules/no-duplicate-fields.md)|Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field.|![recommended][]|🚀
30
+ [no-fragment-cycles](rules/no-fragment-cycles.md)|A GraphQL fragment is only valid when it does not have cycles in fragments usage.|![recommended][]|🔮
31
+ [no-hashtag-description](rules/no-hashtag-description.md)|Requires to use `"""` or `"` for adding a GraphQL description instead of `#`.|![recommended][]|🚀
32
+ [no-root-type](rules/no-root-type.md)|Disallow using root types `mutation` and/or `subscription`.||🚀
33
+ [no-scalar-result-type-on-mutation](rules/no-scalar-result-type-on-mutation.md)|Avoid scalar result type on mutation type to make sure to return a valid state.|![all][]|🚀
34
+ [no-typename-prefix](rules/no-typename-prefix.md)|Enforces users to avoid using the type name in a field name while defining your schema.|![recommended][]|🚀
35
+ [no-undefined-variables](rules/no-undefined-variables.md)|A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.|![recommended][]|🔮
36
+ [no-unreachable-types](rules/no-unreachable-types.md)|Requires all types to be reachable at some level by root level fields.|![recommended][]|🚀
37
+ [no-unused-fields](rules/no-unused-fields.md)|Requires all fields to be used at some level by siblings operations.||🚀
38
+ [no-unused-fragments](rules/no-unused-fragments.md)|A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.|![recommended][]|🔮
39
+ [no-unused-variables](rules/no-unused-variables.md)|A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.|![recommended][]|🔮
40
+ [one-field-subscriptions](rules/one-field-subscriptions.md)|A GraphQL subscription is valid only if it contains a single root field.|![recommended][]|🔮
41
+ [overlapping-fields-can-be-merged](rules/overlapping-fields-can-be-merged.md)|A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.|![recommended][]|🔮
42
+ [possible-fragment-spread](rules/possible-fragment-spread.md)|A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.|![recommended][]|🔮
43
+ [possible-type-extension](rules/possible-type-extension.md)|A type extension is only valid if the type is defined and has the same kind.||🔮
44
+ [provided-required-arguments](rules/provided-required-arguments.md)|A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.|![recommended][]|🔮
45
+ [require-deprecation-date](rules/require-deprecation-date.md)|Require deletion date on `@deprecated` directive. Suggest removing deprecated things after deprecated date.|![all][]|🚀
46
+ [require-deprecation-reason](rules/require-deprecation-reason.md)|Require all deprecation directives to specify a reason.|![recommended][]|🚀
47
+ [require-description](rules/require-description.md)|Enforce descriptions in your type definitions.|![recommended][]|🚀
48
+ [require-field-of-type-query-in-mutation-result](rules/require-field-of-type-query-in-mutation-result.md)|Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.|![all][]|🚀
49
+ [require-id-when-available](rules/require-id-when-available.md)|Enforce selecting specific fields when they are available on the GraphQL type.|![recommended][]|🚀
50
+ [scalar-leafs](rules/scalar-leafs.md)|A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.|![recommended][]|🔮
51
+ [selection-set-depth](rules/selection-set-depth.md)|Limit the complexity of the GraphQL operations solely by their depth. Based on [graphql-depth-limit](https://github.com/stems/graphql-depth-limit).|![recommended][]|🚀
52
+ [strict-id-in-types](rules/strict-id-in-types.md)|Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.|![recommended][]|🚀
53
+ [unique-argument-names](rules/unique-argument-names.md)|A GraphQL field or directive is only valid if all supplied arguments are uniquely named.|![recommended][]|🔮
54
+ [unique-directive-names](rules/unique-directive-names.md)|A GraphQL document is only valid if all defined directives have unique names.|![recommended][]|🔮
55
+ [unique-directive-names-per-location](rules/unique-directive-names-per-location.md)|A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.|![recommended][]|🔮
56
+ [unique-enum-value-names](rules/unique-enum-value-names.md)|A GraphQL enum type is only valid if all its values are uniquely named.||🔮
57
+ [unique-field-definition-names](rules/unique-field-definition-names.md)|A GraphQL complex type is only valid if all its fields are uniquely named.|![recommended][]|🔮
58
+ [unique-fragment-name](rules/unique-fragment-name.md)|Enforce unique fragment names across your project.|![all][]|🚀
59
+ [unique-input-field-names](rules/unique-input-field-names.md)|A GraphQL input object value is only valid if all supplied fields are uniquely named.|![recommended][]|🔮
60
+ [unique-operation-name](rules/unique-operation-name.md)|Enforce unique operation names across your project.|![all][]|🚀
61
+ [unique-operation-types](rules/unique-operation-types.md)|A GraphQL document is only valid if it has only one type per operation.|![recommended][]|🔮
62
+ [unique-type-names](rules/unique-type-names.md)|A GraphQL document is only valid if all defined types have unique names.|![recommended][]|🔮
63
+ [unique-variable-names](rules/unique-variable-names.md)|A GraphQL operation is only valid if all its variables are uniquely named.|![recommended][]|🔮
64
+ [value-literals-of-correct-type](rules/value-literals-of-correct-type.md)|A GraphQL document is only valid if all value literals are of the type expected at their position.|![recommended][]|🔮
65
+ [variables-are-input-types](rules/variables-are-input-types.md)|A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).|![recommended][]|🔮
66
+ [variables-in-allowed-position](rules/variables-in-allowed-position.md)|Variables passed to field arguments conform to type.|![recommended][]|🔮
69
67
  <!-- prettier-ignore-end -->
68
+ [recommended]: https://img.shields.io/badge/-recommended-green.svg
69
+ [all]: https://img.shields.io/badge/-all-blue.svg
@@ -2,8 +2,6 @@
2
2
 
3
3
  ✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file enables this rule.
4
4
 
5
- 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#--fix) can automatically fix some of the problems reported by this rule.
6
-
7
5
  - Category: `Schema`
8
6
  - Rule name: `@graphql-eslint/no-case-insensitive-enum-values-duplicates`
9
7
  - Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
@@ -40,3 +38,4 @@ enum MyEnum {
40
38
  ## Resources
41
39
 
42
40
  - [Rule source](../../packages/plugin/src/rules/no-case-insensitive-enum-values-duplicates.ts)
41
+ - [Test source](../../packages/plugin/tests/no-case-insensitive-enum-values-duplicates.spec.ts)
@@ -2,8 +2,6 @@
2
2
 
3
3
  ✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file enables this rule.
4
4
 
5
- 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#--fix) can automatically fix some of the problems reported by this rule.
6
-
7
5
  - Category: `Schema`
8
6
  - Rule name: `@graphql-eslint/no-unreachable-types`
9
7
  - Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
@@ -1,7 +1,5 @@
1
1
  # `no-unused-fields`
2
2
 
3
- 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#--fix) can automatically fix some of the problems reported by this rule.
4
-
5
3
  - Category: `Schema`
6
4
  - Rule name: `@graphql-eslint/no-unused-fields`
7
5
  - Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
@@ -1,7 +1,5 @@
1
1
  # `unique-enum-value-names`
2
2
 
3
- ✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file enables this rule.
4
-
5
3
  - Category: `Schema`
6
4
  - Rule name: `@graphql-eslint/unique-enum-value-names`
7
5
  - Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
package/index.js CHANGED
@@ -67,7 +67,6 @@ const schemaRecommendedConfig = {
67
67
  '@graphql-eslint/strict-id-in-types': 'error',
68
68
  '@graphql-eslint/unique-directive-names': 'error',
69
69
  '@graphql-eslint/unique-directive-names-per-location': 'error',
70
- '@graphql-eslint/unique-enum-value-names': 'error',
71
70
  '@graphql-eslint/unique-field-definition-names': 'error',
72
71
  '@graphql-eslint/unique-operation-types': 'error',
73
72
  '@graphql-eslint/unique-type-names': 'error',
@@ -89,10 +88,7 @@ const schemaAllConfig = {
89
88
  },
90
89
  ],
91
90
  '@graphql-eslint/input-name': 'error',
92
- '@graphql-eslint/no-root-type': 'off',
93
91
  '@graphql-eslint/no-scalar-result-type-on-mutation': 'error',
94
- '@graphql-eslint/no-unused-fields': 'off',
95
- '@graphql-eslint/possible-type-extension': 'off',
96
92
  '@graphql-eslint/require-deprecation-date': 'error',
97
93
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': 'error',
98
94
  },
@@ -589,6 +585,7 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule('executable-de
589
585
  category: 'Schema',
590
586
  description: `A GraphQL enum type is only valid if all its values are uniquely named.`,
591
587
  requiresSchema: false,
588
+ recommended: false,
592
589
  }), validationToRule('unique-field-definition-names', 'UniqueFieldDefinitionNames', {
593
590
  category: 'Schema',
594
591
  description: `A GraphQL complex type is only valid if all its fields are uniquely named.`,
@@ -1575,12 +1572,11 @@ const rule$5 = {
1575
1572
  },
1576
1573
  };
1577
1574
 
1578
- const ERROR_MESSAGE_ID = 'NO_CASE_INSENSITIVE_ENUM_VALUES_DUPLICATES';
1579
1575
  const rule$6 = {
1580
1576
  meta: {
1581
1577
  type: 'suggestion',
1582
1578
  docs: {
1583
- url: 'https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/no-case-insensitive-enum-values-duplicates.md',
1579
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/no-case-insensitive-enum-values-duplicates.md`,
1584
1580
  category: 'Schema',
1585
1581
  recommended: true,
1586
1582
  description: 'Disallow case-insensitive enum values duplicates.',
@@ -1607,23 +1603,18 @@ const rule$6 = {
1607
1603
  },
1608
1604
  ],
1609
1605
  },
1610
- fixable: 'code',
1611
- messages: {
1612
- [ERROR_MESSAGE_ID]: `Case-insensitive enum values duplicates are not allowed! Found: "{{ found }}"`,
1613
- },
1614
1606
  schema: [],
1615
1607
  },
1616
1608
  create(context) {
1609
+ const selector = [graphql.Kind.ENUM_TYPE_DEFINITION, graphql.Kind.ENUM_TYPE_EXTENSION].join(',');
1617
1610
  return {
1618
- EnumTypeDefinition(node) {
1619
- const foundDuplicates = node.values.filter((item, index) => node.values.findIndex(v => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index);
1620
- for (const dup of foundDuplicates) {
1611
+ [selector](node) {
1612
+ const duplicates = node.values.filter((item, index, array) => array.findIndex(v => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index);
1613
+ for (const duplicate of duplicates) {
1614
+ const enumName = duplicate.name.value;
1621
1615
  context.report({
1622
- node: dup.name,
1623
- data: {
1624
- found: dup.name.value,
1625
- },
1626
- messageId: ERROR_MESSAGE_ID,
1616
+ loc: getLocation(duplicate.loc, enumName),
1617
+ message: `Case-insensitive enum values duplicates are not allowed! Found: "${enumName}"`,
1627
1618
  });
1628
1619
  }
1629
1620
  },
@@ -1854,7 +1845,7 @@ const HASHTAG_COMMENT = 'HASHTAG_COMMENT';
1854
1845
  const rule$9 = {
1855
1846
  meta: {
1856
1847
  messages: {
1857
- [HASHTAG_COMMENT]: 'Using hashtag (#) for adding GraphQL descriptions is not allowed. Prefer using """ for multiline, or " for a single line description.',
1848
+ [HASHTAG_COMMENT]: `Using hashtag (#) for adding GraphQL descriptions is not allowed. Prefer using """ for multiline, or " for a single line description.`,
1858
1849
  },
1859
1850
  docs: {
1860
1851
  description: 'Requires to use `"""` or `"` for adding a GraphQL description instead of `#`.\nAllows to use hashtag for comments, as long as it\'s not attached to an AST definition.',
@@ -1901,14 +1892,15 @@ const rule$9 = {
1901
1892
  schema: [],
1902
1893
  },
1903
1894
  create(context) {
1895
+ const selector = `${graphql.Kind.DOCUMENT}[definitions.0.kind!=/^(${graphql.Kind.OPERATION_DEFINITION}|${graphql.Kind.FRAGMENT_DEFINITION})$/]`;
1904
1896
  return {
1905
- Document(node) {
1897
+ [selector](node) {
1906
1898
  const rawNode = node.rawNode();
1907
1899
  let token = rawNode.loc.startToken;
1908
1900
  while (token !== null) {
1909
1901
  const { kind, prev, next, value, line, column } = token;
1910
1902
  if (kind === graphql.TokenKind.COMMENT && prev && next) {
1911
- const isEslintComment = value.trimLeft().startsWith('eslint');
1903
+ const isEslintComment = value.trimStart().startsWith('eslint');
1912
1904
  const linesAfter = next.line - line;
1913
1905
  if (!isEslintComment && line !== prev.line && next.kind === graphql.TokenKind.NAME && linesAfter < 2) {
1914
1906
  context.report({
@@ -2041,13 +2033,11 @@ const rule$b = {
2041
2033
  }
2042
2034
  const selector = [
2043
2035
  `:matches(${graphql.Kind.OBJECT_TYPE_DEFINITION}, ${graphql.Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
2044
- '>',
2045
- graphql.Kind.FIELD_DEFINITION,
2046
- graphql.Kind.NAMED_TYPE,
2036
+ `> ${graphql.Kind.FIELD_DEFINITION} > .gqlType ${graphql.Kind.NAME}`,
2047
2037
  ].join(' ');
2048
2038
  return {
2049
2039
  [selector](node) {
2050
- const typeName = node.name.value;
2040
+ const typeName = node.value;
2051
2041
  const graphQLType = schema.getType(typeName);
2052
2042
  if (graphql.isScalarType(graphQLType)) {
2053
2043
  context.report({
@@ -2117,7 +2107,22 @@ const rule$c = {
2117
2107
  };
2118
2108
 
2119
2109
  const UNREACHABLE_TYPE = 'UNREACHABLE_TYPE';
2120
- const RULE_NAME = 'no-unreachable-types';
2110
+ const RULE_ID = 'no-unreachable-types';
2111
+ const KINDS = [
2112
+ graphql.Kind.DIRECTIVE_DEFINITION,
2113
+ graphql.Kind.OBJECT_TYPE_DEFINITION,
2114
+ graphql.Kind.OBJECT_TYPE_EXTENSION,
2115
+ graphql.Kind.INTERFACE_TYPE_DEFINITION,
2116
+ graphql.Kind.INTERFACE_TYPE_EXTENSION,
2117
+ graphql.Kind.SCALAR_TYPE_DEFINITION,
2118
+ graphql.Kind.SCALAR_TYPE_EXTENSION,
2119
+ graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION,
2120
+ graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION,
2121
+ graphql.Kind.UNION_TYPE_DEFINITION,
2122
+ graphql.Kind.UNION_TYPE_EXTENSION,
2123
+ graphql.Kind.ENUM_TYPE_DEFINITION,
2124
+ graphql.Kind.ENUM_TYPE_EXTENSION,
2125
+ ];
2121
2126
  const rule$d = {
2122
2127
  meta: {
2123
2128
  messages: {
@@ -2126,7 +2131,7 @@ const rule$d = {
2126
2131
  docs: {
2127
2132
  description: `Requires all types to be reachable at some level by root level fields.`,
2128
2133
  category: 'Schema',
2129
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME}.md`,
2134
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
2130
2135
  requiresSchema: true,
2131
2136
  examples: [
2132
2137
  {
@@ -2158,43 +2163,36 @@ const rule$d = {
2158
2163
  ],
2159
2164
  recommended: true,
2160
2165
  },
2161
- fixable: 'code',
2162
2166
  type: 'suggestion',
2163
2167
  schema: [],
2168
+ hasSuggestions: true,
2164
2169
  },
2165
2170
  create(context) {
2166
- const reachableTypes = requireReachableTypesFromContext(RULE_NAME, context);
2167
- function ensureReachability(node) {
2168
- const typeName = node.name.value;
2169
- if (!reachableTypes.has(typeName)) {
2170
- context.report({
2171
- loc: getLocation(node.name.loc, typeName, { offsetStart: node.kind === graphql.Kind.DIRECTIVE_DEFINITION ? 2 : 1 }),
2172
- messageId: UNREACHABLE_TYPE,
2173
- data: { typeName },
2174
- fix: fixer => fixer.remove(node),
2175
- });
2176
- }
2177
- }
2171
+ const reachableTypes = requireReachableTypesFromContext(RULE_ID, context);
2172
+ const selector = KINDS.join(',');
2178
2173
  return {
2179
- DirectiveDefinition: ensureReachability,
2180
- ObjectTypeDefinition: ensureReachability,
2181
- ObjectTypeExtension: ensureReachability,
2182
- InterfaceTypeDefinition: ensureReachability,
2183
- InterfaceTypeExtension: ensureReachability,
2184
- ScalarTypeDefinition: ensureReachability,
2185
- ScalarTypeExtension: ensureReachability,
2186
- InputObjectTypeDefinition: ensureReachability,
2187
- InputObjectTypeExtension: ensureReachability,
2188
- UnionTypeDefinition: ensureReachability,
2189
- UnionTypeExtension: ensureReachability,
2190
- EnumTypeDefinition: ensureReachability,
2191
- EnumTypeExtension: ensureReachability,
2174
+ [selector](node) {
2175
+ const typeName = node.name.value;
2176
+ if (!reachableTypes.has(typeName)) {
2177
+ context.report({
2178
+ loc: getLocation(node.name.loc, typeName, { offsetStart: node.kind === graphql.Kind.DIRECTIVE_DEFINITION ? 2 : 1 }),
2179
+ messageId: UNREACHABLE_TYPE,
2180
+ data: { typeName },
2181
+ suggest: [
2182
+ {
2183
+ desc: `Remove ${typeName}`,
2184
+ fix: fixer => fixer.remove(node),
2185
+ },
2186
+ ],
2187
+ });
2188
+ }
2189
+ },
2192
2190
  };
2193
2191
  },
2194
2192
  };
2195
2193
 
2196
2194
  const UNUSED_FIELD = 'UNUSED_FIELD';
2197
- const RULE_NAME$1 = 'no-unused-fields';
2195
+ const RULE_ID$1 = 'no-unused-fields';
2198
2196
  const rule$e = {
2199
2197
  meta: {
2200
2198
  messages: {
@@ -2203,7 +2201,7 @@ const rule$e = {
2203
2201
  docs: {
2204
2202
  description: `Requires all fields to be used at some level by siblings operations.`,
2205
2203
  category: 'Schema',
2206
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$1}.md`,
2204
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_ID$1}.md`,
2207
2205
  requiresSiblings: true,
2208
2206
  requiresSchema: true,
2209
2207
  examples: [
@@ -2250,12 +2248,12 @@ const rule$e = {
2250
2248
  },
2251
2249
  ],
2252
2250
  },
2253
- fixable: 'code',
2254
2251
  type: 'suggestion',
2255
2252
  schema: [],
2253
+ hasSuggestions: true,
2256
2254
  },
2257
2255
  create(context) {
2258
- const usedFields = requireUsedFieldsFromContext(RULE_NAME$1, context);
2256
+ const usedFields = requireUsedFieldsFromContext(RULE_ID$1, context);
2259
2257
  return {
2260
2258
  FieldDefinition(node) {
2261
2259
  var _a;
@@ -2269,22 +2267,18 @@ const rule$e = {
2269
2267
  loc: getLocation(node.loc, fieldName),
2270
2268
  messageId: UNUSED_FIELD,
2271
2269
  data: { fieldName },
2272
- fix(fixer) {
2273
- const sourceCode = context.getSourceCode();
2274
- const tokenBefore = sourceCode.getTokenBefore(node);
2275
- const tokenAfter = sourceCode.getTokenAfter(node);
2276
- const isEmptyType = tokenBefore.type === '{' && tokenAfter.type === '}';
2277
- if (isEmptyType) {
2278
- // Remove type
2279
- const { parent } = node;
2280
- const parentBeforeToken = sourceCode.getTokenBefore(parent);
2281
- return parentBeforeToken
2282
- ? fixer.removeRange([parentBeforeToken.range[1], parent.range[1]])
2283
- : fixer.remove(parent);
2284
- }
2285
- // Remove whitespace before token
2286
- return fixer.removeRange([tokenBefore.range[1], node.range[1]]);
2287
- },
2270
+ suggest: [
2271
+ {
2272
+ desc: `Remove "${fieldName}" field`,
2273
+ fix(fixer) {
2274
+ const sourceCode = context.getSourceCode();
2275
+ const tokenBefore = sourceCode.getTokenBefore(node);
2276
+ const tokenAfter = sourceCode.getTokenAfter(node);
2277
+ const isEmptyType = tokenBefore.type === '{' && tokenAfter.type === '}';
2278
+ return isEmptyType ? fixer.remove(node.parent) : fixer.remove(node);
2279
+ },
2280
+ },
2281
+ ],
2288
2282
  });
2289
2283
  },
2290
2284
  };
@@ -2647,14 +2641,14 @@ const rule$h = {
2647
2641
  },
2648
2642
  };
2649
2643
 
2650
- const RULE_NAME$2 = 'require-field-of-type-query-in-mutation-result';
2644
+ const RULE_NAME = 'require-field-of-type-query-in-mutation-result';
2651
2645
  const rule$i = {
2652
2646
  meta: {
2653
2647
  type: 'suggestion',
2654
2648
  docs: {
2655
2649
  category: 'Schema',
2656
2650
  description: 'Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.\n> Currently, no errors are reported for result type `union`, `interface` and `scalar`.',
2657
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$2}.md`,
2651
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME}.md`,
2658
2652
  requiresSchema: true,
2659
2653
  examples: [
2660
2654
  {
@@ -2689,7 +2683,7 @@ const rule$i = {
2689
2683
  schema: [],
2690
2684
  },
2691
2685
  create(context) {
2692
- const schema = requireGraphQLSchemaFromContext(RULE_NAME$2, context);
2686
+ const schema = requireGraphQLSchemaFromContext(RULE_NAME, context);
2693
2687
  const mutationType = schema.getMutationType();
2694
2688
  const queryType = schema.getQueryType();
2695
2689
  if (!mutationType || !queryType) {
@@ -3232,7 +3226,7 @@ const rule$l = {
3232
3226
  },
3233
3227
  };
3234
3228
 
3235
- const RULE_NAME$3 = 'unique-fragment-name';
3229
+ const RULE_NAME$1 = 'unique-fragment-name';
3236
3230
  const UNIQUE_FRAGMENT_NAME = 'UNIQUE_FRAGMENT_NAME';
3237
3231
  const checkNode = (context, node, ruleName, messageId) => {
3238
3232
  const documentName = node.name.value;
@@ -3264,7 +3258,7 @@ const rule$m = {
3264
3258
  docs: {
3265
3259
  category: 'Operations',
3266
3260
  description: `Enforce unique fragment names across your project.`,
3267
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$3}.md`,
3261
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$1}.md`,
3268
3262
  requiresSiblings: true,
3269
3263
  examples: [
3270
3264
  {
@@ -3309,13 +3303,13 @@ const rule$m = {
3309
3303
  create(context) {
3310
3304
  return {
3311
3305
  FragmentDefinition(node) {
3312
- checkNode(context, node, RULE_NAME$3, UNIQUE_FRAGMENT_NAME);
3306
+ checkNode(context, node, RULE_NAME$1, UNIQUE_FRAGMENT_NAME);
3313
3307
  },
3314
3308
  };
3315
3309
  },
3316
3310
  };
3317
3311
 
3318
- const RULE_NAME$4 = 'unique-operation-name';
3312
+ const RULE_NAME$2 = 'unique-operation-name';
3319
3313
  const UNIQUE_OPERATION_NAME = 'UNIQUE_OPERATION_NAME';
3320
3314
  const rule$n = {
3321
3315
  meta: {
@@ -3323,7 +3317,7 @@ const rule$n = {
3323
3317
  docs: {
3324
3318
  category: 'Operations',
3325
3319
  description: `Enforce unique operation names across your project.`,
3326
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$4}.md`,
3320
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$2}.md`,
3327
3321
  requiresSiblings: true,
3328
3322
  examples: [
3329
3323
  {
@@ -3372,7 +3366,7 @@ const rule$n = {
3372
3366
  create(context) {
3373
3367
  return {
3374
3368
  'OperationDefinition[name!=undefined]'(node) {
3375
- checkNode(context, node, RULE_NAME$4, UNIQUE_OPERATION_NAME);
3369
+ checkNode(context, node, RULE_NAME$2, UNIQUE_OPERATION_NAME);
3376
3370
  },
3377
3371
  };
3378
3372
  },
package/index.mjs CHANGED
@@ -61,7 +61,6 @@ const schemaRecommendedConfig = {
61
61
  '@graphql-eslint/strict-id-in-types': 'error',
62
62
  '@graphql-eslint/unique-directive-names': 'error',
63
63
  '@graphql-eslint/unique-directive-names-per-location': 'error',
64
- '@graphql-eslint/unique-enum-value-names': 'error',
65
64
  '@graphql-eslint/unique-field-definition-names': 'error',
66
65
  '@graphql-eslint/unique-operation-types': 'error',
67
66
  '@graphql-eslint/unique-type-names': 'error',
@@ -83,10 +82,7 @@ const schemaAllConfig = {
83
82
  },
84
83
  ],
85
84
  '@graphql-eslint/input-name': 'error',
86
- '@graphql-eslint/no-root-type': 'off',
87
85
  '@graphql-eslint/no-scalar-result-type-on-mutation': 'error',
88
- '@graphql-eslint/no-unused-fields': 'off',
89
- '@graphql-eslint/possible-type-extension': 'off',
90
86
  '@graphql-eslint/require-deprecation-date': 'error',
91
87
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': 'error',
92
88
  },
@@ -583,6 +579,7 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule('executable-de
583
579
  category: 'Schema',
584
580
  description: `A GraphQL enum type is only valid if all its values are uniquely named.`,
585
581
  requiresSchema: false,
582
+ recommended: false,
586
583
  }), validationToRule('unique-field-definition-names', 'UniqueFieldDefinitionNames', {
587
584
  category: 'Schema',
588
585
  description: `A GraphQL complex type is only valid if all its fields are uniquely named.`,
@@ -1569,12 +1566,11 @@ const rule$5 = {
1569
1566
  },
1570
1567
  };
1571
1568
 
1572
- const ERROR_MESSAGE_ID = 'NO_CASE_INSENSITIVE_ENUM_VALUES_DUPLICATES';
1573
1569
  const rule$6 = {
1574
1570
  meta: {
1575
1571
  type: 'suggestion',
1576
1572
  docs: {
1577
- url: 'https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/no-case-insensitive-enum-values-duplicates.md',
1573
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/no-case-insensitive-enum-values-duplicates.md`,
1578
1574
  category: 'Schema',
1579
1575
  recommended: true,
1580
1576
  description: 'Disallow case-insensitive enum values duplicates.',
@@ -1601,23 +1597,18 @@ const rule$6 = {
1601
1597
  },
1602
1598
  ],
1603
1599
  },
1604
- fixable: 'code',
1605
- messages: {
1606
- [ERROR_MESSAGE_ID]: `Case-insensitive enum values duplicates are not allowed! Found: "{{ found }}"`,
1607
- },
1608
1600
  schema: [],
1609
1601
  },
1610
1602
  create(context) {
1603
+ const selector = [Kind.ENUM_TYPE_DEFINITION, Kind.ENUM_TYPE_EXTENSION].join(',');
1611
1604
  return {
1612
- EnumTypeDefinition(node) {
1613
- const foundDuplicates = node.values.filter((item, index) => node.values.findIndex(v => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index);
1614
- for (const dup of foundDuplicates) {
1605
+ [selector](node) {
1606
+ const duplicates = node.values.filter((item, index, array) => array.findIndex(v => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index);
1607
+ for (const duplicate of duplicates) {
1608
+ const enumName = duplicate.name.value;
1615
1609
  context.report({
1616
- node: dup.name,
1617
- data: {
1618
- found: dup.name.value,
1619
- },
1620
- messageId: ERROR_MESSAGE_ID,
1610
+ loc: getLocation(duplicate.loc, enumName),
1611
+ message: `Case-insensitive enum values duplicates are not allowed! Found: "${enumName}"`,
1621
1612
  });
1622
1613
  }
1623
1614
  },
@@ -1848,7 +1839,7 @@ const HASHTAG_COMMENT = 'HASHTAG_COMMENT';
1848
1839
  const rule$9 = {
1849
1840
  meta: {
1850
1841
  messages: {
1851
- [HASHTAG_COMMENT]: 'Using hashtag (#) for adding GraphQL descriptions is not allowed. Prefer using """ for multiline, or " for a single line description.',
1842
+ [HASHTAG_COMMENT]: `Using hashtag (#) for adding GraphQL descriptions is not allowed. Prefer using """ for multiline, or " for a single line description.`,
1852
1843
  },
1853
1844
  docs: {
1854
1845
  description: 'Requires to use `"""` or `"` for adding a GraphQL description instead of `#`.\nAllows to use hashtag for comments, as long as it\'s not attached to an AST definition.',
@@ -1895,14 +1886,15 @@ const rule$9 = {
1895
1886
  schema: [],
1896
1887
  },
1897
1888
  create(context) {
1889
+ const selector = `${Kind.DOCUMENT}[definitions.0.kind!=/^(${Kind.OPERATION_DEFINITION}|${Kind.FRAGMENT_DEFINITION})$/]`;
1898
1890
  return {
1899
- Document(node) {
1891
+ [selector](node) {
1900
1892
  const rawNode = node.rawNode();
1901
1893
  let token = rawNode.loc.startToken;
1902
1894
  while (token !== null) {
1903
1895
  const { kind, prev, next, value, line, column } = token;
1904
1896
  if (kind === TokenKind.COMMENT && prev && next) {
1905
- const isEslintComment = value.trimLeft().startsWith('eslint');
1897
+ const isEslintComment = value.trimStart().startsWith('eslint');
1906
1898
  const linesAfter = next.line - line;
1907
1899
  if (!isEslintComment && line !== prev.line && next.kind === TokenKind.NAME && linesAfter < 2) {
1908
1900
  context.report({
@@ -2035,13 +2027,11 @@ const rule$b = {
2035
2027
  }
2036
2028
  const selector = [
2037
2029
  `:matches(${Kind.OBJECT_TYPE_DEFINITION}, ${Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
2038
- '>',
2039
- Kind.FIELD_DEFINITION,
2040
- Kind.NAMED_TYPE,
2030
+ `> ${Kind.FIELD_DEFINITION} > .gqlType ${Kind.NAME}`,
2041
2031
  ].join(' ');
2042
2032
  return {
2043
2033
  [selector](node) {
2044
- const typeName = node.name.value;
2034
+ const typeName = node.value;
2045
2035
  const graphQLType = schema.getType(typeName);
2046
2036
  if (isScalarType(graphQLType)) {
2047
2037
  context.report({
@@ -2111,7 +2101,22 @@ const rule$c = {
2111
2101
  };
2112
2102
 
2113
2103
  const UNREACHABLE_TYPE = 'UNREACHABLE_TYPE';
2114
- const RULE_NAME = 'no-unreachable-types';
2104
+ const RULE_ID = 'no-unreachable-types';
2105
+ const KINDS = [
2106
+ Kind.DIRECTIVE_DEFINITION,
2107
+ Kind.OBJECT_TYPE_DEFINITION,
2108
+ Kind.OBJECT_TYPE_EXTENSION,
2109
+ Kind.INTERFACE_TYPE_DEFINITION,
2110
+ Kind.INTERFACE_TYPE_EXTENSION,
2111
+ Kind.SCALAR_TYPE_DEFINITION,
2112
+ Kind.SCALAR_TYPE_EXTENSION,
2113
+ Kind.INPUT_OBJECT_TYPE_DEFINITION,
2114
+ Kind.INPUT_OBJECT_TYPE_EXTENSION,
2115
+ Kind.UNION_TYPE_DEFINITION,
2116
+ Kind.UNION_TYPE_EXTENSION,
2117
+ Kind.ENUM_TYPE_DEFINITION,
2118
+ Kind.ENUM_TYPE_EXTENSION,
2119
+ ];
2115
2120
  const rule$d = {
2116
2121
  meta: {
2117
2122
  messages: {
@@ -2120,7 +2125,7 @@ const rule$d = {
2120
2125
  docs: {
2121
2126
  description: `Requires all types to be reachable at some level by root level fields.`,
2122
2127
  category: 'Schema',
2123
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME}.md`,
2128
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
2124
2129
  requiresSchema: true,
2125
2130
  examples: [
2126
2131
  {
@@ -2152,43 +2157,36 @@ const rule$d = {
2152
2157
  ],
2153
2158
  recommended: true,
2154
2159
  },
2155
- fixable: 'code',
2156
2160
  type: 'suggestion',
2157
2161
  schema: [],
2162
+ hasSuggestions: true,
2158
2163
  },
2159
2164
  create(context) {
2160
- const reachableTypes = requireReachableTypesFromContext(RULE_NAME, context);
2161
- function ensureReachability(node) {
2162
- const typeName = node.name.value;
2163
- if (!reachableTypes.has(typeName)) {
2164
- context.report({
2165
- loc: getLocation(node.name.loc, typeName, { offsetStart: node.kind === Kind.DIRECTIVE_DEFINITION ? 2 : 1 }),
2166
- messageId: UNREACHABLE_TYPE,
2167
- data: { typeName },
2168
- fix: fixer => fixer.remove(node),
2169
- });
2170
- }
2171
- }
2165
+ const reachableTypes = requireReachableTypesFromContext(RULE_ID, context);
2166
+ const selector = KINDS.join(',');
2172
2167
  return {
2173
- DirectiveDefinition: ensureReachability,
2174
- ObjectTypeDefinition: ensureReachability,
2175
- ObjectTypeExtension: ensureReachability,
2176
- InterfaceTypeDefinition: ensureReachability,
2177
- InterfaceTypeExtension: ensureReachability,
2178
- ScalarTypeDefinition: ensureReachability,
2179
- ScalarTypeExtension: ensureReachability,
2180
- InputObjectTypeDefinition: ensureReachability,
2181
- InputObjectTypeExtension: ensureReachability,
2182
- UnionTypeDefinition: ensureReachability,
2183
- UnionTypeExtension: ensureReachability,
2184
- EnumTypeDefinition: ensureReachability,
2185
- EnumTypeExtension: ensureReachability,
2168
+ [selector](node) {
2169
+ const typeName = node.name.value;
2170
+ if (!reachableTypes.has(typeName)) {
2171
+ context.report({
2172
+ loc: getLocation(node.name.loc, typeName, { offsetStart: node.kind === Kind.DIRECTIVE_DEFINITION ? 2 : 1 }),
2173
+ messageId: UNREACHABLE_TYPE,
2174
+ data: { typeName },
2175
+ suggest: [
2176
+ {
2177
+ desc: `Remove ${typeName}`,
2178
+ fix: fixer => fixer.remove(node),
2179
+ },
2180
+ ],
2181
+ });
2182
+ }
2183
+ },
2186
2184
  };
2187
2185
  },
2188
2186
  };
2189
2187
 
2190
2188
  const UNUSED_FIELD = 'UNUSED_FIELD';
2191
- const RULE_NAME$1 = 'no-unused-fields';
2189
+ const RULE_ID$1 = 'no-unused-fields';
2192
2190
  const rule$e = {
2193
2191
  meta: {
2194
2192
  messages: {
@@ -2197,7 +2195,7 @@ const rule$e = {
2197
2195
  docs: {
2198
2196
  description: `Requires all fields to be used at some level by siblings operations.`,
2199
2197
  category: 'Schema',
2200
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$1}.md`,
2198
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_ID$1}.md`,
2201
2199
  requiresSiblings: true,
2202
2200
  requiresSchema: true,
2203
2201
  examples: [
@@ -2244,12 +2242,12 @@ const rule$e = {
2244
2242
  },
2245
2243
  ],
2246
2244
  },
2247
- fixable: 'code',
2248
2245
  type: 'suggestion',
2249
2246
  schema: [],
2247
+ hasSuggestions: true,
2250
2248
  },
2251
2249
  create(context) {
2252
- const usedFields = requireUsedFieldsFromContext(RULE_NAME$1, context);
2250
+ const usedFields = requireUsedFieldsFromContext(RULE_ID$1, context);
2253
2251
  return {
2254
2252
  FieldDefinition(node) {
2255
2253
  var _a;
@@ -2263,22 +2261,18 @@ const rule$e = {
2263
2261
  loc: getLocation(node.loc, fieldName),
2264
2262
  messageId: UNUSED_FIELD,
2265
2263
  data: { fieldName },
2266
- fix(fixer) {
2267
- const sourceCode = context.getSourceCode();
2268
- const tokenBefore = sourceCode.getTokenBefore(node);
2269
- const tokenAfter = sourceCode.getTokenAfter(node);
2270
- const isEmptyType = tokenBefore.type === '{' && tokenAfter.type === '}';
2271
- if (isEmptyType) {
2272
- // Remove type
2273
- const { parent } = node;
2274
- const parentBeforeToken = sourceCode.getTokenBefore(parent);
2275
- return parentBeforeToken
2276
- ? fixer.removeRange([parentBeforeToken.range[1], parent.range[1]])
2277
- : fixer.remove(parent);
2278
- }
2279
- // Remove whitespace before token
2280
- return fixer.removeRange([tokenBefore.range[1], node.range[1]]);
2281
- },
2264
+ suggest: [
2265
+ {
2266
+ desc: `Remove "${fieldName}" field`,
2267
+ fix(fixer) {
2268
+ const sourceCode = context.getSourceCode();
2269
+ const tokenBefore = sourceCode.getTokenBefore(node);
2270
+ const tokenAfter = sourceCode.getTokenAfter(node);
2271
+ const isEmptyType = tokenBefore.type === '{' && tokenAfter.type === '}';
2272
+ return isEmptyType ? fixer.remove(node.parent) : fixer.remove(node);
2273
+ },
2274
+ },
2275
+ ],
2282
2276
  });
2283
2277
  },
2284
2278
  };
@@ -2641,14 +2635,14 @@ const rule$h = {
2641
2635
  },
2642
2636
  };
2643
2637
 
2644
- const RULE_NAME$2 = 'require-field-of-type-query-in-mutation-result';
2638
+ const RULE_NAME = 'require-field-of-type-query-in-mutation-result';
2645
2639
  const rule$i = {
2646
2640
  meta: {
2647
2641
  type: 'suggestion',
2648
2642
  docs: {
2649
2643
  category: 'Schema',
2650
2644
  description: 'Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.\n> Currently, no errors are reported for result type `union`, `interface` and `scalar`.',
2651
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$2}.md`,
2645
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME}.md`,
2652
2646
  requiresSchema: true,
2653
2647
  examples: [
2654
2648
  {
@@ -2683,7 +2677,7 @@ const rule$i = {
2683
2677
  schema: [],
2684
2678
  },
2685
2679
  create(context) {
2686
- const schema = requireGraphQLSchemaFromContext(RULE_NAME$2, context);
2680
+ const schema = requireGraphQLSchemaFromContext(RULE_NAME, context);
2687
2681
  const mutationType = schema.getMutationType();
2688
2682
  const queryType = schema.getQueryType();
2689
2683
  if (!mutationType || !queryType) {
@@ -3226,7 +3220,7 @@ const rule$l = {
3226
3220
  },
3227
3221
  };
3228
3222
 
3229
- const RULE_NAME$3 = 'unique-fragment-name';
3223
+ const RULE_NAME$1 = 'unique-fragment-name';
3230
3224
  const UNIQUE_FRAGMENT_NAME = 'UNIQUE_FRAGMENT_NAME';
3231
3225
  const checkNode = (context, node, ruleName, messageId) => {
3232
3226
  const documentName = node.name.value;
@@ -3258,7 +3252,7 @@ const rule$m = {
3258
3252
  docs: {
3259
3253
  category: 'Operations',
3260
3254
  description: `Enforce unique fragment names across your project.`,
3261
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$3}.md`,
3255
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$1}.md`,
3262
3256
  requiresSiblings: true,
3263
3257
  examples: [
3264
3258
  {
@@ -3303,13 +3297,13 @@ const rule$m = {
3303
3297
  create(context) {
3304
3298
  return {
3305
3299
  FragmentDefinition(node) {
3306
- checkNode(context, node, RULE_NAME$3, UNIQUE_FRAGMENT_NAME);
3300
+ checkNode(context, node, RULE_NAME$1, UNIQUE_FRAGMENT_NAME);
3307
3301
  },
3308
3302
  };
3309
3303
  },
3310
3304
  };
3311
3305
 
3312
- const RULE_NAME$4 = 'unique-operation-name';
3306
+ const RULE_NAME$2 = 'unique-operation-name';
3313
3307
  const UNIQUE_OPERATION_NAME = 'UNIQUE_OPERATION_NAME';
3314
3308
  const rule$n = {
3315
3309
  meta: {
@@ -3317,7 +3311,7 @@ const rule$n = {
3317
3311
  docs: {
3318
3312
  category: 'Operations',
3319
3313
  description: `Enforce unique operation names across your project.`,
3320
- url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$4}.md`,
3314
+ url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_NAME$2}.md`,
3321
3315
  requiresSiblings: true,
3322
3316
  examples: [
3323
3317
  {
@@ -3366,7 +3360,7 @@ const rule$n = {
3366
3360
  create(context) {
3367
3361
  return {
3368
3362
  'OperationDefinition[name!=undefined]'(node) {
3369
- checkNode(context, node, RULE_NAME$4, UNIQUE_OPERATION_NAME);
3363
+ checkNode(context, node, RULE_NAME$2, UNIQUE_OPERATION_NAME);
3370
3364
  },
3371
3365
  };
3372
3366
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.0.1-alpha-86a9e78.0",
3
+ "version": "3.1.0",
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 || ^16.0.0"
@@ -8,7 +8,7 @@
8
8
  "dependencies": {
9
9
  "@babel/code-frame": "7.16.0",
10
10
  "@graphql-tools/code-file-loader": "7.2.2",
11
- "@graphql-tools/graphql-tag-pluck": "7.1.3",
11
+ "@graphql-tools/graphql-tag-pluck": "7.1.4",
12
12
  "@graphql-tools/import": "6.6.1",
13
13
  "@graphql-tools/utils": "8.5.3",
14
14
  "graphql-config": "4.1.0",