Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dimitri POSTOLOV
committed
Oct 20, 2021
1 parent
12ee95a
commit c7a8b33
Showing
26 changed files
with
800 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-eslint/eslint-plugin': minor | ||
--- | ||
|
||
add new rule `alphabetize` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# `alphabetize` | ||
|
||
- Category: `Best Practices` | ||
- Rule name: `@graphql-eslint/alphabetize` | ||
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema) | ||
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations) | ||
|
||
Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more. | ||
|
||
## Usage Examples | ||
|
||
### Incorrect | ||
|
||
```graphql | ||
# eslint @graphql-eslint/alphabetize: ['error', { fields: ['ObjectTypeDefinition'] }] | ||
|
||
type User { | ||
password: String | ||
firstName: String! # should be before "password" | ||
age: Int # should be before "firstName" | ||
lastName: String! | ||
} | ||
``` | ||
|
||
### Correct | ||
|
||
```graphql | ||
# eslint @graphql-eslint/alphabetize: ['error', { fields: ['ObjectTypeDefinition'] }] | ||
|
||
type User { | ||
age: Int | ||
firstName: String! | ||
lastName: String! | ||
password: String | ||
} | ||
``` | ||
|
||
### Incorrect | ||
|
||
```graphql | ||
# eslint @graphql-eslint/alphabetize: ['error', { values: ['EnumTypeDefinition'] }] | ||
|
||
enum Role { | ||
SUPER_ADMIN | ||
ADMIN # should be before "SUPER_ADMIN" | ||
USER | ||
GOD # should be before "USER" | ||
} | ||
``` | ||
|
||
### Correct | ||
|
||
```graphql | ||
# eslint @graphql-eslint/alphabetize: ['error', { values: ['EnumTypeDefinition'] }] | ||
|
||
enum Role { | ||
ADMIN | ||
GOD | ||
SUPER_ADMIN | ||
USER | ||
} | ||
``` | ||
|
||
### Incorrect | ||
|
||
```graphql | ||
# eslint @graphql-eslint/alphabetize: ['error', { selections: ['OperationDefinition'] }] | ||
|
||
query { | ||
me { | ||
firstName | ||
lastName | ||
email # should be before "lastName" | ||
} | ||
} | ||
``` | ||
|
||
### Correct | ||
|
||
```graphql | ||
# eslint @graphql-eslint/alphabetize: ['error', { selections: ['OperationDefinition'] }] | ||
|
||
query { | ||
me { | ||
firstName | ||
lastName | ||
} | ||
} | ||
``` | ||
|
||
## Config Schema | ||
|
||
The schema defines the following properties: | ||
|
||
### `fields` (array) | ||
|
||
Fields of `type`, `interface`, and `input`. | ||
|
||
The elements of the array must contain the following properties: | ||
|
||
- `ObjectTypeDefinition` | ||
- `InterfaceTypeDefinition` | ||
- `InputObjectTypeDefinition` | ||
|
||
### `values` (array) | ||
|
||
Values of `enum`. | ||
|
||
The elements of the array must contain the following properties: | ||
|
||
- `EnumTypeDefinition` | ||
|
||
### `selections` (array) | ||
|
||
Selections of operations (`query`, `mutation` and `subscription`) and `fragment`. | ||
|
||
The elements of the array must contain the following properties: | ||
|
||
- `OperationDefinition` | ||
- `FragmentDefinition` | ||
|
||
### `variables` (array) | ||
|
||
Variables of operations (`query`, `mutation` and `subscription`). | ||
|
||
The elements of the array must contain the following properties: | ||
|
||
- `OperationDefinition` | ||
|
||
### `arguments` (array) | ||
|
||
Arguments of fields and directives. | ||
|
||
The elements of the array must contain the following properties: | ||
|
||
- `FieldDefinition` | ||
- `Field` | ||
- `DirectiveDefinition` | ||
- `Directive` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.