@graphql-eslint/eslint-plugin 2.3.0-alpha-6ba4002.0 → 2.4.0-alpha-be7d9d8.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.
package/README.md CHANGED
@@ -46,7 +46,7 @@ npm install --save-dev @graphql-eslint/eslint-plugin
46
46
 
47
47
  ### Configuration
48
48
 
49
- To get started, create an override configuration for your ESLint, while applying it to to `.graphql` files (do that even if you are declaring your operations in code files):
49
+ To get started, create an override configuration for your ESLint, while applying it to `.graphql` files (do that even if you are declaring your operations in code files):
50
50
 
51
51
  ```json
52
52
  {
package/configs/all.d.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  export declare const allConfig: {
2
2
  rules: {
3
+ '@graphql-eslint/alphabetize': (string | {
4
+ fields: string[];
5
+ values: string[];
6
+ selections: string[];
7
+ variables: string[];
8
+ arguments: string[];
9
+ })[];
3
10
  '@graphql-eslint/avoid-duplicate-fields': string;
4
11
  '@graphql-eslint/avoid-operation-name-prefix': string;
5
12
  '@graphql-eslint/avoid-scalar-result-type-on-mutation': string;
@@ -1,6 +1,13 @@
1
1
  export declare const configs: {
2
2
  all: {
3
3
  rules: {
4
+ '@graphql-eslint/alphabetize': (string | {
5
+ fields: string[];
6
+ values: string[];
7
+ selections: string[];
8
+ variables: string[];
9
+ arguments: string[];
10
+ })[];
4
11
  '@graphql-eslint/avoid-duplicate-fields': string;
5
12
  '@graphql-eslint/avoid-operation-name-prefix': string;
6
13
  '@graphql-eslint/avoid-scalar-result-type-on-mutation': string;
package/docs/README.md CHANGED
@@ -11,6 +11,7 @@ Each rule has emojis denoting:
11
11
  <!-- prettier-ignore-start -->
12
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
13
  -|-|:-:|-|-
14
+ [alphabetize](rules/alphabetize.md)|Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.|🚀||
14
15
  [avoid-duplicate-fields](rules/avoid-duplicate-fields.md)|Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field.|🚀||
15
16
  [avoid-operation-name-prefix](rules/avoid-operation-name-prefix.md)|Enforce/avoid operation name prefix, useful if you wish to avoid prefix in your root fields, or avoid using REST terminology in your schema.|🚀||
16
17
  [avoid-scalar-result-type-on-mutation](rules/avoid-scalar-result-type-on-mutation.md)|Avoid scalar result type on mutation type to make sure to return a valid state.|🚀||
@@ -38,7 +38,7 @@ const rule: GraphQLESLintRule = {
38
38
  So what happens here?
39
39
 
40
40
  1. `@graphql-eslint/eslint-plugin` handles the parsing process for your GraphQL content. It will load the GraphQL files (either from code files or from `.graphql` files with SDL), parse it using GraphQL parser, converts it to ESTree structure and let ESLint do the rest.
41
- 1. You rule is being loaded by ESLint, and executes just like any other ESLint rule.
41
+ 1. Your rule is being loaded by ESLint, and executes just like any other ESLint rule.
42
42
  1. Our custom rule asks ESLint to run our function for every `OperationDefinition` found.
43
43
  1. If the `OperationDefinition` node doesn't have a valid `name` - we report an error to ESLint.
44
44
 
@@ -49,7 +49,7 @@ You can scan the `packages/plugin/src/rules` directory in this repo for referenc
49
49
  ## Accessing original GraphQL AST nodes
50
50
 
51
51
  Since our parser converts GraphQL AST to ESTree structure, there are some minor differences in the structure of the objects.
52
- If you are using TypeScript, and you typed your rule with `GraphQLESLintRule` - you'll see that each `node` is a bit different from from the AST nodes of GraphQL (you can read more about that in [graphql-eslint parser documentation](./parser.md)).
52
+ If you are using TypeScript, and you typed your rule with `GraphQLESLintRule` - you'll see that each `node` is a bit different from the AST nodes of GraphQL (you can read more about that in [graphql-eslint parser documentation](./parser.md)).
53
53
 
54
54
  If you need access to the original GraphQL AST `node`, you can use `.rawNode()` method on each node you get from the AST structure of ESLint.
55
55
 
@@ -0,0 +1,140 @@
1
+ # `alphabetize`
2
+
3
+ - Category: `Best Practices`
4
+ - Rule name: `@graphql-eslint/alphabetize`
5
+ - Requires GraphQL Schema: `false` [â„šī¸](../../README.md#extended-linting-rules-with-graphql-schema)
6
+ - Requires GraphQL Operations: `false` [â„šī¸](../../README.md#extended-linting-rules-with-siblings-operations)
7
+
8
+ Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.
9
+
10
+ ## Usage Examples
11
+
12
+ ### Incorrect
13
+
14
+ ```graphql
15
+ # eslint @graphql-eslint/alphabetize: ['error', { fields: ['ObjectTypeDefinition'] }]
16
+
17
+ type User {
18
+ password: String
19
+ firstName: String! # should be before "password"
20
+ age: Int # should be before "firstName"
21
+ lastName: String!
22
+ }
23
+ ```
24
+
25
+ ### Correct
26
+
27
+ ```graphql
28
+ # eslint @graphql-eslint/alphabetize: ['error', { fields: ['ObjectTypeDefinition'] }]
29
+
30
+ type User {
31
+ age: Int
32
+ firstName: String!
33
+ lastName: String!
34
+ password: String
35
+ }
36
+ ```
37
+
38
+ ### Incorrect
39
+
40
+ ```graphql
41
+ # eslint @graphql-eslint/alphabetize: ['error', { values: ['EnumTypeDefinition'] }]
42
+
43
+ enum Role {
44
+ SUPER_ADMIN
45
+ ADMIN # should be before "SUPER_ADMIN"
46
+ USER
47
+ GOD # should be before "USER"
48
+ }
49
+ ```
50
+
51
+ ### Correct
52
+
53
+ ```graphql
54
+ # eslint @graphql-eslint/alphabetize: ['error', { values: ['EnumTypeDefinition'] }]
55
+
56
+ enum Role {
57
+ ADMIN
58
+ GOD
59
+ SUPER_ADMIN
60
+ USER
61
+ }
62
+ ```
63
+
64
+ ### Incorrect
65
+
66
+ ```graphql
67
+ # eslint @graphql-eslint/alphabetize: ['error', { selections: ['OperationDefinition'] }]
68
+
69
+ query {
70
+ me {
71
+ firstName
72
+ lastName
73
+ email # should be before "lastName"
74
+ }
75
+ }
76
+ ```
77
+
78
+ ### Correct
79
+
80
+ ```graphql
81
+ # eslint @graphql-eslint/alphabetize: ['error', { selections: ['OperationDefinition'] }]
82
+
83
+ query {
84
+ me {
85
+ email
86
+ firstName
87
+ lastName
88
+ }
89
+ }
90
+ ```
91
+
92
+ ## Config Schema
93
+
94
+ The schema defines the following properties:
95
+
96
+ ### `fields` (array)
97
+
98
+ Fields of `type`, `interface`, and `input`.
99
+
100
+ The elements of the array must contain the following properties:
101
+
102
+ - `ObjectTypeDefinition`
103
+ - `InterfaceTypeDefinition`
104
+ - `InputObjectTypeDefinition`
105
+
106
+ ### `values` (array)
107
+
108
+ Values of `enum`.
109
+
110
+ The elements of the array must contain the following properties:
111
+
112
+ - `EnumTypeDefinition`
113
+
114
+ ### `selections` (array)
115
+
116
+ Selections of operations (`query`, `mutation` and `subscription`) and `fragment`.
117
+
118
+ The elements of the array must contain the following properties:
119
+
120
+ - `OperationDefinition`
121
+ - `FragmentDefinition`
122
+
123
+ ### `variables` (array)
124
+
125
+ Variables of operations (`query`, `mutation` and `subscription`).
126
+
127
+ The elements of the array must contain the following properties:
128
+
129
+ - `OperationDefinition`
130
+
131
+ ### `arguments` (array)
132
+
133
+ Arguments of fields and directives.
134
+
135
+ The elements of the array must contain the following properties:
136
+
137
+ - `FieldDefinition`
138
+ - `Field`
139
+ - `DirectiveDefinition`
140
+ - `Directive`
@@ -31,17 +31,13 @@ query userDetails {
31
31
 
32
32
  ## Config Schema
33
33
 
34
- ### (array)
34
+ The schema defines the following properties:
35
35
 
36
- The schema defines an array with all elements of the type `object`.
37
-
38
- The array object has the following properties:
39
-
40
- #### `caseSensitive` (boolean)
36
+ ### `caseSensitive` (boolean)
41
37
 
42
38
  Default: `false`
43
39
 
44
- #### `keywords` (array, required)
40
+ ### `keywords` (array, required)
45
41
 
46
42
  The object is an array with all elements of the type `string`.
47
43
 
@@ -16,7 +16,7 @@ Require all comments to follow the same style (either block or inline).
16
16
 
17
17
  """ Description """
18
18
  type someTypeName {
19
- ...
19
+ # ...
20
20
  }
21
21
  ```
22
22
 
@@ -27,19 +27,15 @@ type someTypeName {
27
27
 
28
28
  " Description "
29
29
  type someTypeName {
30
- ...
30
+ # ...
31
31
  }
32
32
  ```
33
33
 
34
34
  ## Config Schema
35
35
 
36
- ### (array)
36
+ The schema defines the following properties:
37
37
 
38
- The schema defines an array with all elements of the type `object`.
39
-
40
- The array object has the following properties:
41
-
42
- #### `style` (string, enum)
38
+ ### `style` (string, enum)
43
39
 
44
40
  This element must be one of the following enum values:
45
41
 
@@ -42,31 +42,27 @@ type Mutation {
42
42
 
43
43
  ## Config Schema
44
44
 
45
- ### (array)
45
+ The schema defines the following properties:
46
46
 
47
- The schema defines an array with all elements of the type `object`.
48
-
49
- The array object has the following properties:
50
-
51
- #### `checkInputType` (boolean)
47
+ ### `checkInputType` (boolean)
52
48
 
53
49
  Check that the input type name follows the convention <mutationName>Input
54
50
 
55
51
  Default: `false`
56
52
 
57
- #### `caseSensitiveInputType` (boolean)
53
+ ### `caseSensitiveInputType` (boolean)
58
54
 
59
55
  Allow for case discrepancies in the input type name
60
56
 
61
57
  Default: `true`
62
58
 
63
- #### `checkQueries` (boolean)
59
+ ### `checkQueries` (boolean)
64
60
 
65
61
  Apply the rule to Queries
66
62
 
67
63
  Default: `false`
68
64
 
69
- #### `checkMutations` (boolean)
65
+ ### `checkMutations` (boolean)
70
66
 
71
67
  Apply the rule to Mutations
72
68
 
@@ -86,41 +86,37 @@ query UserById {
86
86
 
87
87
  ## Config Schema
88
88
 
89
- ### (array)
89
+ The schema defines the following properties:
90
90
 
91
- The schema defines an array with all elements of the type `object`.
92
-
93
- The array object has the following properties:
94
-
95
- #### `fileExtension` (string, enum)
91
+ ### `fileExtension` (string, enum)
96
92
 
97
93
  This element must be one of the following enum values:
98
94
 
99
95
  * `.gql`
100
96
  * `.graphql`
101
97
 
102
- #### `query`
98
+ ### `query`
103
99
 
104
100
  The object must be one of the following types:
105
101
 
106
102
  * `asString`
107
103
  * `asObject`
108
104
 
109
- #### `mutation`
105
+ ### `mutation`
110
106
 
111
107
  The object must be one of the following types:
112
108
 
113
109
  * `asString`
114
110
  * `asObject`
115
111
 
116
- #### `subscription`
112
+ ### `subscription`
117
113
 
118
114
  The object must be one of the following types:
119
115
 
120
116
  * `asString`
121
117
  * `asObject`
122
118
 
123
- #### `fragment`
119
+ ### `fragment`
124
120
 
125
121
  The object must be one of the following types:
126
122
 
@@ -33,97 +33,93 @@ type SomeTypeName {
33
33
 
34
34
  ## Config Schema
35
35
 
36
- ### (array)
36
+ The schema defines the following properties:
37
37
 
38
- The schema defines an array with all elements of the type `object`.
39
-
40
- The array object has the following properties:
41
-
42
- #### `FieldDefinition`
38
+ ### `FieldDefinition`
43
39
 
44
40
  The object must be one of the following types:
45
41
 
46
42
  * `asString`
47
43
  * `asObject`
48
44
 
49
- #### `InputObjectTypeDefinition`
45
+ ### `InputObjectTypeDefinition`
50
46
 
51
47
  The object must be one of the following types:
52
48
 
53
49
  * `asString`
54
50
  * `asObject`
55
51
 
56
- #### `EnumValueDefinition`
52
+ ### `EnumValueDefinition`
57
53
 
58
54
  The object must be one of the following types:
59
55
 
60
56
  * `asString`
61
57
  * `asObject`
62
58
 
63
- #### `InputValueDefinition`
59
+ ### `InputValueDefinition`
64
60
 
65
61
  The object must be one of the following types:
66
62
 
67
63
  * `asString`
68
64
  * `asObject`
69
65
 
70
- #### `ObjectTypeDefinition`
66
+ ### `ObjectTypeDefinition`
71
67
 
72
68
  The object must be one of the following types:
73
69
 
74
70
  * `asString`
75
71
  * `asObject`
76
72
 
77
- #### `InterfaceTypeDefinition`
73
+ ### `InterfaceTypeDefinition`
78
74
 
79
75
  The object must be one of the following types:
80
76
 
81
77
  * `asString`
82
78
  * `asObject`
83
79
 
84
- #### `EnumTypeDefinition`
80
+ ### `EnumTypeDefinition`
85
81
 
86
82
  The object must be one of the following types:
87
83
 
88
84
  * `asString`
89
85
  * `asObject`
90
86
 
91
- #### `UnionTypeDefinition`
87
+ ### `UnionTypeDefinition`
92
88
 
93
89
  The object must be one of the following types:
94
90
 
95
91
  * `asString`
96
92
  * `asObject`
97
93
 
98
- #### `ScalarTypeDefinition`
94
+ ### `ScalarTypeDefinition`
99
95
 
100
96
  The object must be one of the following types:
101
97
 
102
98
  * `asString`
103
99
  * `asObject`
104
100
 
105
- #### `OperationDefinition`
101
+ ### `OperationDefinition`
106
102
 
107
103
  The object must be one of the following types:
108
104
 
109
105
  * `asString`
110
106
  * `asObject`
111
107
 
112
- #### `FragmentDefinition`
108
+ ### `FragmentDefinition`
113
109
 
114
110
  The object must be one of the following types:
115
111
 
116
112
  * `asString`
117
113
  * `asObject`
118
114
 
119
- #### `QueryDefinition`
115
+ ### `QueryDefinition`
120
116
 
121
117
  The object must be one of the following types:
122
118
 
123
119
  * `asString`
124
120
  * `asObject`
125
121
 
126
- #### `leadingUnderscore` (string, enum)
122
+ ### `leadingUnderscore` (string, enum)
127
123
 
128
124
  This element must be one of the following enum values:
129
125
 
@@ -132,7 +128,7 @@ This element must be one of the following enum values:
132
128
 
133
129
  Default: `"forbid"`
134
130
 
135
- #### `trailingUnderscore` (string, enum)
131
+ ### `trailingUnderscore` (string, enum)
136
132
 
137
133
  This element must be one of the following enum values:
138
134
 
@@ -44,10 +44,6 @@ type User {
44
44
 
45
45
  ## Config Schema
46
46
 
47
- ### (array)
47
+ The schema defines the following properties:
48
48
 
49
- The schema defines an array with all elements of the type `object`.
50
-
51
- The array object has the following properties:
52
-
53
- #### `argumentName` (string)
49
+ ### `argumentName` (string)
@@ -37,20 +37,12 @@ type someTypeName {
37
37
 
38
38
  ## Config Schema
39
39
 
40
- ### (array)
40
+ The schema defines the following properties:
41
41
 
42
- The schema defines an array with all elements of the type `object`.
43
-
44
- The array object has the following properties:
45
-
46
- #### `on` (array)
42
+ ### `on` (array)
47
43
 
48
44
  The object is an array with all elements of the type `string`.
49
45
 
50
46
  Additional restrictions:
51
47
 
52
- * Minimum items: `1`
53
-
54
- Additional restrictions:
55
-
56
48
  * Minimum items: `1`
@@ -50,12 +50,8 @@ query user {
50
50
 
51
51
  ## Config Schema
52
52
 
53
- ### (array)
53
+ The schema defines the following properties:
54
54
 
55
- The schema defines an array with all elements of the type `object`.
56
-
57
- The array object has the following properties:
58
-
59
- #### `fieldName` (string)
55
+ ### `fieldName` (string)
60
56
 
61
57
  Default: `"id"`
@@ -53,18 +53,10 @@ query deep2 {
53
53
 
54
54
  ## Config Schema
55
55
 
56
- ### (array)
56
+ The schema defines the following properties:
57
57
 
58
- The schema defines an array with all elements of the type `object`.
58
+ ### `maxDepth` (number)
59
59
 
60
- The array object has the following properties:
60
+ ### `ignore` (array)
61
61
 
62
- #### `maxDepth` (number)
63
-
64
- #### `ignore` (array)
65
-
66
- The object is an array with all elements of the type `string`.
67
-
68
- Additional restrictions:
69
-
70
- * Minimum items: `1`
62
+ The object is an array with all elements of the type `string`.
@@ -62,13 +62,9 @@ type Error {
62
62
 
63
63
  ## Config Schema
64
64
 
65
- ### (array)
65
+ The schema defines the following properties:
66
66
 
67
- The schema defines an array with all elements of the type `object`.
68
-
69
- The array object has the following properties:
70
-
71
- #### `acceptedIdNames` (array)
67
+ ### `acceptedIdNames` (array)
72
68
 
73
69
  The object is an array with all elements of the type `string`.
74
70
 
@@ -80,7 +76,7 @@ Default:
80
76
  ]
81
77
  ```
82
78
 
83
- #### `acceptedIdTypes` (array)
79
+ ### `acceptedIdTypes` (array)
84
80
 
85
81
  The object is an array with all elements of the type `string`.
86
82
 
@@ -92,11 +88,11 @@ Default:
92
88
  ]
93
89
  ```
94
90
 
95
- #### `exceptions` (object)
91
+ ### `exceptions` (object)
96
92
 
97
93
  Properties of the `exceptions` object:
98
94
 
99
- ##### `types` (array)
95
+ #### `types` (array)
100
96
 
101
97
  This is used to exclude types with names that match one of the specified values.
102
98
 
@@ -108,7 +104,7 @@ Default:
108
104
  []
109
105
  ```
110
106
 
111
- ##### `suffixes` (array)
107
+ #### `suffixes` (array)
112
108
 
113
109
  This is used to exclude types with names with suffixes that match one of the specified values.
114
110
 
@@ -1,7 +1,6 @@
1
1
  import { GraphQLESTreeNode } from './estree-ast';
2
2
  import { ASTNode, TypeInfo } from 'graphql';
3
- import { Comment } from 'estree';
4
3
  export declare function convertToESTree<T extends ASTNode>(node: T, typeInfo?: TypeInfo): {
5
- rootTree: GraphQLESTreeNode<T>;
6
- comments: Comment[];
4
+ rootTree: GraphQLESTreeNode<T, false>;
5
+ comments: import("estree").Comment[];
7
6
  };
@@ -5,7 +5,7 @@ export declare type SafeGraphQLType<T extends ASTNode | ValueNode> = Omit<T exte
5
5
  } ? Omit<T, 'type'> & {
6
6
  readonly gqlType: TypeNode;
7
7
  } : T, 'loc'>;
8
- export declare type SingleESTreeNode<T extends any, WithTypeInfo extends boolean> = T extends ASTNode | ValueNode ? SafeGraphQLType<T> & Pick<BaseNode, 'leadingComments' | 'loc' | 'range'> & {
8
+ export declare type SingleESTreeNode<T, WithTypeInfo extends boolean> = T extends ASTNode | ValueNode ? SafeGraphQLType<T> & Pick<BaseNode, 'leadingComments' | 'loc' | 'range'> & {
9
9
  type: T['kind'];
10
10
  gqlLocation: Location;
11
11
  } & (WithTypeInfo extends true ? {
@@ -21,7 +21,7 @@ export declare type SingleESTreeNode<T extends any, WithTypeInfo extends boolean
21
21
  gqlType?: ReturnType<TypeInfo['getType']>;
22
22
  };
23
23
  } : {}) : T;
24
- export declare type GraphQLESTreeNode<T extends any, WithTypeInfo extends boolean = false> = T extends ASTNode | ValueNode ? {
24
+ export declare type GraphQLESTreeNode<T, WithTypeInfo extends boolean = false> = T extends ASTNode | ValueNode ? {
25
25
  rawNode: () => T;
26
26
  } & {
27
27
  [K in keyof SingleESTreeNode<T, WithTypeInfo>]: SingleESTreeNode<T, WithTypeInfo>[K] extends ReadonlyArray<infer Nested> ? GraphQLESTreeNode<Nested, WithTypeInfo>[] : SingleESTreeNode<T, WithTypeInfo>[K] extends ASTNode ? GraphQLESTreeNode<SingleESTreeNode<T, WithTypeInfo>[K], WithTypeInfo> : SingleESTreeNode<T, WithTypeInfo>[K];