Skip to content

Commit b7eb87e

Browse files
authored
added new rule for unique-fragment-name and added self-documenting rules (#229)
1 parent 1f61dd1 commit b7eb87e

39 files changed

+969
-292
lines changed

.changeset/tidy-hornets-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': minor
3+
---
4+
5+
New rule: unique-fragment-name

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ To get started, create an override configuration for your ESLint, while applying
5656
"parser": "@graphql-eslint/eslint-plugin",
5757
"plugins": ["@graphql-eslint"],
5858
"rules": {
59-
"eol-last": "off",
60-
"prettier/prettier": "off"
6159
...
6260
}
6361
}
@@ -79,16 +77,13 @@ If you are using code files to store your GraphQL schema or your GraphQL operati
7977
"parser": "@graphql-eslint/eslint-plugin",
8078
"plugins": ["@graphql-eslint"],
8179
"rules": {
82-
"eol-last": "off",
83-
"prettier/prettier": "off"
80+
...
8481
}
8582
}
8683
]
8784
}
8885
```
8986

90-
> Note: Make sure to disable `eol-last` and `prettier/prettier` - otherwise, you might get an error (see https://github.com/dotansimha/graphql-eslint/issues/88).
91-
9287
#### Extended linting rules with GraphQL Schema
9388

9489
If you are using [`graphql-config`](https://graphql-config.com/) - you are good to go. This package integrates with it automatically, and will use it to load your schema!
Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,50 @@
1-
## Avoid Prefix in GraphQL operation name
1+
# `avoid-operation-name-prefix`
22

3-
- Name: `avoid-operation-name-prefix`
3+
- Category: `Stylistic Issues`
4+
- Rule name: `@graphql-eslint/avoid-operation-name-prefix`
45
- Requires GraphQL Schema: `false`
6+
- Requires GraphQL Operations: `false`
57

6-
Allow you to enforce and avoid operation name prefix, useful if you wish to avoid prefix in your root fields,like `getSomething`.
8+
Enforce/avoid operation name prefix, useful if you wish to avoid prefix in your root fields, or avoid using REST terminology in your schema
79

8-
### Usage Example
10+
## Usage Examples
911

10-
Examples of **incorrect** code for this rule:
12+
### Incorrect
1113

1214
```graphql
13-
# eslint @graphql-eslint/avoid-operation-name-prefix: ["error", { keywords: ["get"] }]
15+
# eslint @graphql-eslint/avoid-operation-name-prefix: ["error", [{"keywords":["get"]}]]
1416

1517
query getUserDetails {
1618
# ...
1719
}
1820
```
1921

20-
Examples of **correct** code for this rule:
22+
### Correct
2123

2224
```graphql
23-
# eslint @graphql-eslint/avoid-operation-name-prefix: ["error", { keywords: ["get"] }]
25+
# eslint @graphql-eslint/avoid-operation-name-prefix: ["error", [{"keywords":["get"]}]]
2426

2527
query userDetails {
2628
# ...
2729
}
2830
```
2931

30-
### Configuration
32+
## Config Schema
3133

32-
- `keywords`: array of prefixes you with to avoid in operation names.
34+
### (array)
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)
41+
42+
Default: `false`
43+
44+
#### `keywords` (array, required)
45+
46+
The object is an array with all elements of the type `string`.
47+
48+
Additional restrictions:
49+
50+
* Minimum items: `1`

docs/rules/description-style.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
1-
# Enforce style of the description comments
1+
# `description-style`
22

3-
- Name: `description-style`
3+
- Category: `Stylistic Issues`
4+
- Rule name: `@graphql-eslint/description-style`
45
- Requires GraphQL Schema: `false`
6+
- Requires GraphQL Operations: `false`
57

6-
Following the same style for description comments in your code will make them easier to read.
8+
Require all comments to follow the same style (either block or inline)
79

8-
## Rule Details
10+
## Usage Examples
911

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:
12+
### Incorrect
1313

1414
```graphql
15-
# eslint @graphql-eslint/description-style: ["error", { style: "inline" }]
15+
# eslint @graphql-eslint/description-style: ["error", [{"style":"inline"}]]
1616

1717
""" Description """
1818
type someTypeName {
1919
...
2020
}
2121
```
2222

23-
Examples of **correct** code for this rule:
23+
### Correct
2424

2525
```graphql
26-
# eslint @graphql-eslint/description-style: ["error", { style: "inline" }]
26+
# eslint @graphql-eslint/description-style: ["error", [{"style":"inline"}]]
2727

2828
" Description "
29-
type SomeTypeName {
30-
someFieldName: String
29+
type someTypeName {
30+
...
3131
}
3232
```
3333

34-
## Options
34+
## Config Schema
35+
36+
### (array)
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)
43+
44+
This element must be one of the following enum values:
3545

36-
This rule accepts configuration object with one option:
46+
* `block`
47+
* `inline`
3748

38-
- `style: 'block'|'inline'` - Will require all comments to be either in block style (`"""`) or inline style (`"`)
49+
Default: `"inline"`

docs/rules/input-name.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,53 @@
1-
# Enforce names of input parameters and input types
1+
# `input-name`
22

3-
- Name: `input-name`
3+
- Category: `Stylistic Issues`
4+
- Rule name: `@graphql-eslint/input-name`
45
- Requires GraphQL Schema: `false`
6+
- Requires GraphQL Operations: `false`
57

8+
Require mutation argument to be always called "input" and input type to be called Mutation name + "Input".
69
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.
710

8-
## Rule Details
11+
## Usage Examples
912

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+
### Incorrect
1314

1415
```graphql
15-
# eslint @graphql-eslint/input-name: ["error", { checkInputType: true }]
16+
# eslint @graphql-eslint/input-name: ["error", [{"checkInputType":true}]]
1617

1718
type Mutation {
1819
SetMessage(message: InputMessage): String
1920
}
2021
```
2122

22-
Examples of **correct** code for this rule:
23+
### Correct (with checkInputType)
2324

2425
```graphql
25-
# eslint @graphql-eslint/input-name: ["error", { checkInputType: true }]
26+
# eslint @graphql-eslint/input-name: ["error", [{"checkInputType":true}]]
2627

2728
type Mutation {
2829
SetMessage(input: SetMessageInput): String
2930
}
3031
```
3132

33+
### Correct (without checkInputType)
34+
3235
```graphql
33-
# eslint @graphql-eslint/input-name: ["error", { checkInputType: false }]
36+
# eslint @graphql-eslint/input-name: ["error", [{"checkInputType":false}]]
3437

3538
type Mutation {
3639
SetMessage(input: AnyInputTypeName): String
3740
}
3841
```
3942

40-
## Configuration
43+
## Config Schema
44+
45+
### (array)
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)
4152

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.
53+
Default: `"true"`

0 commit comments

Comments
 (0)