Skip to content

Commit f6c5355

Browse files
committed
fixes
1 parent 4070697 commit f6c5355

17 files changed

+457
-12
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ This project integrates GraphQL AST parser and ESLint.
22

33
## Key Features:
44

5-
🚀 Integrates with ESLint core (as a ESTree parser).
6-
🚀 Works on `.graphql` files, `gql` usages and `/* GraphQL */` magic comments.
7-
🚀 Lints both GraphQL schema and GraphQL operations.
8-
🚀 Extended type info for more advanced usages
9-
🚀 Supports ESLint directives (for example: `disable-next-line`)
10-
🚀 Easily extendable - supports custom rules.
5+
- 🚀 Integrates with ESLint core (as a ESTree parser).
6+
- 🚀 Works on `.graphql` files, `gql` usages and `/* GraphQL */` magic comments.
7+
- 🚀 Lints both GraphQL schema and GraphQL operations.
8+
- 🚀 Extended type info for more advanced usages
9+
- 🚀 Supports ESLint directives (for example: `disable-next-line`)
10+
- 🚀 Easily extendable - supports custom rules.
1111

1212
Special thanks to [ilyavolodin](https://github.com/ilyavolodin) for his work on a similar project!
1313

@@ -101,6 +101,6 @@ In order to enable it processing other extensions, add the following section in
101101

102102
## Available Rules
103103

104-
You can find a complete list of [all available plugins here](./RULES.md)
104+
You can find a complete list of [all available plugins here](./docs/README.md)
105105

106106
> This repo doesn't exports a "recommended" set of rules - feel free to recommend us!

RULES.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Available Rules
2+
3+
- [`avoid-operation-name-prefix`](./avoid-operation-name-prefix.md)
4+
- [`input-name`](./input-name.md)
5+
- [`description-style`](./description-style.md)
6+
- [`naming-convention`](./naming-convention.md)
7+
- [`no-anonymous-operations`](./no-anonymous-operations.md)
8+
- [`require-deprecation-reason`](./require-deprecation-reason.md)
9+
- [`no-case-insensitive-enum-values-duplicates`](./no-case-insensitive-enum-values-duplicates.md)
10+
- [`no-operation-name-suffix`](./no-operation-name-suffix.md)
11+
- [`require-id-when-available`](./require-id-when-available.md)
12+
- [`validate-against-schema`](./validate-against-schema.md)
13+
- [`prettier`](./prettier.md)
14+
- [`require-description`](./require-description.md)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Avoid Prefix in GraphQL operation name
2+
3+
- Name: `avoid-operation-name-prefix`
4+
- Requires GraphQL Schema: `false`
5+
6+
Allow you to enforce and avoid operation name prefix, useful if you wish to avoid prefix in your root fields,like `getSomething`.
7+
8+
### Usage Example
9+
10+
Examples of **incorrect** code for this rule:
11+
12+
```graphql
13+
# eslint @graphql-eslint/avoid-operation-name-prefix: ["error", { keywords: "get" }]
14+
15+
query getUserDetails {
16+
# ...
17+
}
18+
```
19+
20+
Examples of **correct** code for this rule:
21+
22+
```graphql
23+
# eslint @graphql-eslint/avoid-operation-name-prefix: ["error", { keywords: "get" }]
24+
25+
query userDetails {
26+
# ...
27+
}
28+
```
29+
30+
### Configuration
31+
32+
- `keywords`: array of prefixes you with to avoid in operation names.

docs/rules/description-style.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Enforce style of the description comments
2+
3+
- Name: `description-style`
4+
- Requires GraphQL Schema: `false`
5+
6+
Following the same style for description comments in your code will make them easier to read.
7+
8+
## Rule Details
9+
10+
This rule enforces same style for all description comments in your code. This rule has one option: `style` that can be set to either `block` or `inline` (default).
11+
12+
Examples of **incorrect** code for this rule:
13+
14+
```graphql
15+
# eslint @graphql-eslint/description-style: ["error", { style: "inline" }]
16+
17+
""" Description """
18+
type someTypeName {
19+
...
20+
}
21+
```
22+
23+
Examples of **correct** code for this rule:
24+
25+
```graphql
26+
# eslint @graphql-eslint/description-style: ["error", { style: "inline" }]
27+
28+
" Description "
29+
type SomeTypeName {
30+
someFieldName: String
31+
}
32+
```
33+
34+
## Options
35+
36+
This rule accepts configuration object with one option:
37+
38+
- `style: 'block'|'inline'` - Will require all comments to be either in block style (`"""`) or inline style (`"`)

docs/rules/input-name.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Enforce names of input parameters and input types
2+
3+
- Name: `input-name`
4+
- Requires GraphQL Schema: `false`
5+
6+
Using the same name for all input parameters will make your schemas easier to consume and more predictable. Using the same name as mutation for InputType will make it easier to find mutations that InputType belongs to.
7+
8+
## Rule Details
9+
10+
This rule enforces all input parameters to be named `input`, and all InputTypes to use the name of the mutation + `'Input'`.
11+
12+
Examples of **incorrect** code for this rule:
13+
14+
```graphql
15+
# eslint @graphql-eslint/input-name: ["error", { checkInputType: true }]
16+
17+
type Mutation {
18+
SetMessage(message: InputMessage): String
19+
}
20+
```
21+
22+
Examples of **correct** code for this rule:
23+
24+
```graphql
25+
# eslint @graphql-eslint/input-name: ["error", { checkInputType: true }]
26+
27+
type Mutation {
28+
SetMessage(input: SetMessageInput): String
29+
}
30+
```
31+
32+
```graphql
33+
# eslint @graphql-eslint/input-name: ["error", { checkInputType: false }]
34+
35+
type Mutation {
36+
SetMessage(input: AnyInputTypeName): String
37+
}
38+
```
39+
40+
## Configuration
41+
42+
This rule accepts one option `checkInputType`. If `true` (default) it will verify that the name of the input type matches name of the mutation + 'Input'. If `false` it will not check InputType name.

docs/rules/naming-convention.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Enforce naming conventions patterns in your typeDefs
2+
3+
- Name: `naming-convention`
4+
- Requires GraphQL Schema: `false`
5+
6+
Following the same naming conventions in all your type definitions will make them easier to read and more predictable.
7+
8+
## Rule Details
9+
10+
This rule enforces naming conventions patterns for your type definitions. It can control if the names should be in PascalCase, camelCase, snake_case or UPPER_CASE. It can also allow or disallow trailing and leading underscores.
11+
12+
Examples of **incorrect** code for this rule:
13+
14+
```graphql
15+
# eslint @graphql-eslint/naming-convention: ["error", { ObjectTypeDefinition: "PascalCase" }]
16+
17+
type someTypeName {
18+
...
19+
}
20+
```
21+
22+
Examples of **correct** code for this rule:
23+
24+
```graphql
25+
# eslint @graphql-eslint/naming-convention: ["error", { FieldDefinition: "camelCase", ObjectTypeDefinition: "PascalCase" }]
26+
27+
type SomeTypeName {
28+
someFieldName: String
29+
}
30+
```
31+
32+
## Options
33+
34+
This rule accepts configuration object with multiple options:
35+
36+
- `ObjectTypeDefinition: 'PascalCase'|'camelCase'|'snake_case'|'UPPER_CASE'` - Will affect names of types, input objects, enums and interfaces
37+
- `FieldDefinition: 'PascalCase'|'camelCase'|'snake_case'|'UPPER_CASE'` - Will affect names of type fields
38+
- `EnumValueDefinition: 'PascalCase'|'camelCase'|'snake_case'|'UPPER_CASE'` - Will affect names of enumeration values
39+
- `InputValueDefinition: 'PascalCase'|'camelCase'|'snake_case'|'UPPER_CASE'` - Will affect names of input properties
40+
- `FragmentDefinition: 'PascalCase'|'camelCase'|'snake_case'|'UPPER_CASE'` - Will affect names of fragments
41+
- `ScalarTypeDefinition: 'PascalCase'|'camelCase'|'snake_case'|'UPPER_CASE'` - Will affect names of scalars
42+
- `leadingUnderscore: 'allow'|'forbid'` - Will allow or forbid leading underscores in all names. Default value is `forbid`.
43+
- `trailingUnderscore: 'allow'|'forbid'` - Will allow of forbid trailing underscores in all names. Default value is `forbid`.

docs/rules/no-anonymous-operations.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Avoid Anonymous GraphQL operations
2+
3+
- Name: `no-anonymous-operations`
4+
- Requires GraphQL Schema: `false`
5+
6+
Allow you to require name for your GraphQL operations. This is useful since most GraphQL client libraries are using the operation name for caching purposes.
7+
8+
### Usage Example
9+
10+
Examples of **incorrect** code for this rule:
11+
12+
```graphql
13+
# eslint @graphql-eslint/no-anonymous-operations: ["error"]
14+
15+
query {
16+
# ...
17+
}
18+
```
19+
20+
Examples of **correct** code for this rule:
21+
22+
```graphql
23+
# eslint @graphql-eslint/no-anonymous-operations: ["error"]
24+
25+
query something {
26+
# ...
27+
}
28+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Avoid Duplicates In Enum Values
2+
3+
- Name: `no-case-insensitive-enum-values-duplicates`
4+
- Requires GraphQL Schema: `false`
5+
6+
Checks enums values for duplicate values defined (case-insensitive).
7+
8+
### Usage Example
9+
10+
Examples of **incorrect** code for this rule:
11+
12+
```graphql
13+
# eslint @graphql-eslint/no-case-insensitive-enum-values-duplicates: ["error"]
14+
15+
enum MyEnum {
16+
Value
17+
VALUE
18+
ValuE
19+
}
20+
```
21+
22+
Examples of **correct** code for this rule:
23+
24+
```graphql
25+
# eslint @graphql-eslint/no-case-insensitive-enum-values-duplicates: ["error"]
26+
27+
enum MyEnum {
28+
Value1
29+
Value2
30+
Value3
31+
}
32+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## No Operation Name Suffix
2+
3+
- Name: `no-operation-name-suffix`
4+
- Requires GraphQL Schema: `false`
5+
6+
Makes sure you are not adding the operation type to the name of the operation.
7+
8+
### Usage Example
9+
10+
Examples of **incorrect** code for this rule:
11+
12+
```graphql
13+
# eslint @graphql-eslint/no-operation-name-suffix: ["error"]
14+
15+
query userQuery {
16+
# ...
17+
}
18+
```
19+
20+
Examples of **correct** code for this rule:
21+
22+
```graphql
23+
# eslint @graphql-eslint/no-operation-name-suffix: ["error"]
24+
25+
query user {
26+
# ...
27+
}
28+
```

0 commit comments

Comments
 (0)