-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
馃帀 NEW RULE: Compare operation/fragment name to the file name (#458)
- Loading branch information
1 parent
7b12bbf
commit c6886ba
Showing
18 changed files
with
717 additions
and
204 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 | ||
--- | ||
|
||
[New rule] Compare operation/fragment name to the file name |
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': patch | ||
--- | ||
|
||
NEW PLUGIN: Compare operation/fragment name to the file name |
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,152 @@ | ||
# `match-document-filename` | ||
|
||
- Category: `Best Practices` | ||
- Rule name: `@graphql-eslint/match-document-filename` | ||
- Requires GraphQL Schema: `false` [鈩癸笍](../../README.md#extended-linting-rules-with-graphql-schema) | ||
- Requires GraphQL Operations: `false` [鈩癸笍](../../README.md#extended-linting-rules-with-siblings-operations) | ||
|
||
This rule allows you to enforce that the file name should match the operation name | ||
|
||
## Usage Examples | ||
|
||
### Correct | ||
|
||
```graphql | ||
# eslint @graphql-eslint/match-document-filename: ['error', { fileExtension: '.gql' }] | ||
|
||
# user.gql | ||
type User { | ||
id: ID! | ||
} | ||
``` | ||
|
||
### Correct | ||
|
||
```graphql | ||
# eslint @graphql-eslint/match-document-filename: ['error', { query: 'snake_case' }] | ||
|
||
# user_by_id.gql | ||
query UserById { | ||
userById(id: 5) { | ||
id | ||
name | ||
fullName | ||
} | ||
} | ||
``` | ||
|
||
### Correct | ||
|
||
```graphql | ||
# eslint @graphql-eslint/match-document-filename: ['error', { fragment: { style: 'kebab-case', suffix: '.fragment' } }] | ||
|
||
# user-fields.fragment.gql | ||
fragment user_fields on User { | ||
id | ||
} | ||
``` | ||
|
||
### Correct | ||
|
||
```graphql | ||
# eslint @graphql-eslint/match-document-filename: ['error', { mutation: { style: 'PascalCase', suffix: 'Mutation' } }] | ||
|
||
# DeleteUserMutation.gql | ||
mutation DELETE_USER { | ||
deleteUser(id: 5) | ||
} | ||
``` | ||
|
||
### Incorrect | ||
|
||
```graphql | ||
# eslint @graphql-eslint/match-document-filename: ['error', { fileExtension: '.graphql' }] | ||
|
||
# post.gql | ||
type Post { | ||
id: ID! | ||
} | ||
``` | ||
|
||
### Incorrect | ||
|
||
```graphql | ||
# eslint @graphql-eslint/match-document-filename: ['error', { query: 'PascalCase' }] | ||
|
||
# user-by-id.gql | ||
query UserById { | ||
userById(id: 5) { | ||
id | ||
name | ||
fullName | ||
} | ||
} | ||
``` | ||
|
||
## Config Schema | ||
|
||
### (array) | ||
|
||
The schema defines an array with all elements of the type `object`. | ||
|
||
The array object has the following properties: | ||
|
||
#### `fileExtension` (string, enum) | ||
|
||
This element must be one of the following enum values: | ||
|
||
* `.gql` | ||
* `.graphql` | ||
|
||
#### `query` | ||
|
||
The object must be one of the following types: | ||
|
||
* `asString` | ||
* `asObject` | ||
|
||
#### `mutation` | ||
|
||
The object must be one of the following types: | ||
|
||
* `asString` | ||
* `asObject` | ||
|
||
#### `subscription` | ||
|
||
The object must be one of the following types: | ||
|
||
* `asString` | ||
* `asObject` | ||
|
||
#### `fragment` | ||
|
||
The object must be one of the following types: | ||
|
||
* `asString` | ||
* `asObject` | ||
|
||
--- | ||
|
||
# Sub Schemas | ||
|
||
The schema defines the following additional types: | ||
|
||
## `asString` (string) | ||
|
||
One of: `camelCase`, `PascalCase`, `snake_case`, `UPPER_CASE`, `kebab-case` | ||
|
||
## `asObject` (object) | ||
|
||
Properties of the `asObject` object: | ||
|
||
### `style` (string, enum) | ||
|
||
This element must be one of the following enum values: | ||
|
||
* `camelCase` | ||
* `PascalCase` | ||
* `snake_case` | ||
* `UPPER_CASE` | ||
* `kebab-case` |
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.