Skip to content

Commit 70136fd

Browse files
author
Dimitri POSTOLOV
authored
fix README.md (#772)
* prettify `README.md` and `custom-rules.md` * fix readme
1 parent f4d41b1 commit 70136fd

File tree

3 files changed

+91
-119
lines changed

3 files changed

+91
-119
lines changed

.prettierrc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,14 @@
22
"trailingComma": "es5",
33
"printWidth": 120,
44
"singleQuote": true,
5-
"arrowParens": "avoid"
5+
"arrowParens": "avoid",
6+
"overrides": [
7+
{
8+
"files": "*.md",
9+
"options": {
10+
"semi": false,
11+
"trailingComma": "none"
12+
}
13+
}
14+
]
615
}

README.md

Lines changed: 45 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ This project integrates GraphQL and ESLint, for a better developer experience.
66

77
[![npm version](https://badge.fury.io/js/%40graphql-eslint%2Feslint-plugin.svg)](https://badge.fury.io/js/%40graphql-eslint%2Feslint-plugin)
88

9-
> Created and maintained by [The Guild](http://the-guild.dev/)
9+
> Created and maintained by [The Guild](http://the-guild.dev)
1010
1111
## Key Features
1212

13-
- 🚀 Integrates with ESLint core (as a ESTree parser).
14-
- 🚀 Works on `.graphql` files, `gql` usages and `/* GraphQL */` magic comments.
15-
- 🚀 Lints both GraphQL schema and GraphQL operations.
13+
- 🚀 Integrates with ESLint core (as a ESTree parser)
14+
- 🚀 Works on `.graphql` files, `gql` usages and `/* GraphQL */` magic comments
15+
- 🚀 Lints both GraphQL schema and GraphQL operations
1616
- 🚀 Extended type info for more advanced usages
17-
- 🚀 Supports ESLint directives (for example: `disable-next-line`)
18-
- 🚀 Easily extendable - supports custom rules based on GraphQL's AST and ESLint API.
19-
- 🚀 Validates, lints, prettifies and checks for best practices across GraphQL schema and GraphQL operations.
20-
- 🚀 Integrates with [`graphql-config`](https://graphql-config.com/)
17+
- 🚀 Supports ESLint directives (for example: `eslint-disable-next-line`)
18+
- 🚀 Easily extendable - supports custom rules based on GraphQL's AST and ESLint API
19+
- 🚀 Validates, lints, prettifies and checks for best practices across GraphQL schema and GraphQL operations
20+
- 🚀 Integrates with [`graphql-config`](https://graphql-config.com)
2121
- 🚀 Integrates and visualizes lint issues in popular IDEs (VSCode / WebStorm)
2222

2323
> Special thanks to [ilyavolodin](https://github.com/ilyavolodin) for his work on a similar project!
@@ -42,15 +42,13 @@ Or, with NPM:
4242
npm install --save-dev @graphql-eslint/eslint-plugin
4343
```
4444

45-
> Also, make sure you have `graphql` dependency in your project.
45+
> Make sure you have `graphql` dependency in your project.
4646
4747
### Configuration
4848

49-
#### Tell ESLint to apply this plugin to `.graphql` files.
49+
To get started, define an override in your ESLint config to apply this plugin to `.graphql` files. Add the [rules](docs/README.md) you want applied.
5050

51-
_This step is necessary even if you are declaring operations and/or schema in code files._
52-
53-
To get started, define an override in your ESLint config to tell ESLint to modify the way it treats `.graphql` files. Add the [rules](./docs/README.md) you want applied.
51+
> 🚨 Important! This step is necessary even if you are declaring operations and/or schema in code files.
5452
5553
```json
5654
{
@@ -60,73 +58,47 @@ To get started, define an override in your ESLint config to tell ESLint to modif
6058
"parser": "@graphql-eslint/eslint-plugin",
6159
"plugins": ["@graphql-eslint"],
6260
"rules": {
63-
"@graphql-eslint/require-description": [
64-
"error",
65-
{
66-
"on": [
67-
"ObjectTypeDefinition",
68-
"InterfaceTypeDefinition",
69-
"EnumTypeDefinition",
70-
"InputObjectTypeDefinition",
71-
"UnionTypeDefinition",
72-
"FieldDefinition",
73-
"DirectiveDefinition",
74-
],
75-
},
76-
],
61+
"@graphql-eslint/known-type-names": "error"
7762
}
7863
}
7964
]
8065
}
8166
```
8267

83-
If your GraphQL definitions are defined only in `.graphql` files and you're only using rules that apply to individual files, you should be good to go 👍 . If you would like use a remote schema or use rules that apply across the entire collection of definitions at once, see [here](#using-rules-with-constraints-that-span-the-entire-schema).
68+
If your GraphQL definitions are defined only in `.graphql` files, and you're only using rules that apply to individual files, you should be good to go 👍. If you would like use a remote schema or use rules that apply across the entire collection of definitions at once, see [here](#using-a-remote-schema-or-rules-with-constraints-that-span-the-entire-schema).
8469

85-
#### Tell ESLint to apply this plugin to GraphQL definitions defined in code files.
70+
#### Tell ESLint to apply this plugin to GraphQL definitions defined in code files
8671

8772
If you are defining GraphQL schema or GraphQL operations in code files, you'll want to define an additional override to extend the functionality of this plugin to the schema and operations in those files.
8873

8974
```diff
9075
{
9176
"overrides": [
9277
+ {
93-
+ "files": ["*.tsx", "*.ts", "*.jsx", "*.js"],
78+
+ "files": ["*.js"],
9479
+ "processor": "@graphql-eslint/graphql"
9580
+ },
9681
{
9782
"files": ["*.graphql"],
9883
"parser": "@graphql-eslint/eslint-plugin",
9984
"plugins": ["@graphql-eslint"],
10085
"rules": {
101-
"@graphql-eslint/require-description": [
102-
"error",
103-
{
104-
"on": [
105-
"ObjectTypeDefinition",
106-
"InterfaceTypeDefinition",
107-
"EnumTypeDefinition",
108-
"InputObjectTypeDefinition",
109-
"UnionTypeDefinition",
110-
"FieldDefinition",
111-
"DirectiveDefinition",
112-
],
113-
},
114-
],
86+
"@graphql-eslint/known-type-names": "error"
11587
}
11688
}
11789
]
11890
}
11991
```
12092

121-
Under the hood, specifying the `@graphql-eslint/graphql` processor for code files will cause `graphql-eslint/graphql` to extract the schema and operation definitions from these files into virtual GraphQL documents with `.graphql` extensions. This will allow the overrides you've defined for `.graphql` files, via `files: ["*.graphql"]`, to get applied to the definitions defined in your code files.
93+
Under the hood, specifying the `@graphql-eslint/graphql` processor for code files will cause `graphql-eslint/graphql` to extract the schema and operation definitions from these files into virtual GraphQL documents with `.graphql` extensions. This will allow the overrides you've defined for `.graphql` files, via `"files": ["*.graphql"]`, to get applied to the definitions defined in your code files.
12294

123-
#### Using a remote schema or rules with constraints that span the entire schema.
95+
#### Using a remote schema or rules with constraints that span the entire schema
12496

12597
Some rules require an understanding of the entire schema at once. For example, [no-unreachable-types](https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/no-unreachable-types.md#no-unreachable-types) checks that all types are reachable by root-level fields.
12698

12799
To use these rules, you'll need to tell ESLint how to identify the entire set of schema definitions.
128100

129-
If you are using [`graphql-config`](https://graphql-config.com/), you are good to go. `graphql-eslint` integrates with it automatically and will use it to load your schema!
101+
If you are using [`graphql-config`](https://graphql-config.com), you are good to go. `graphql-eslint` integrates with it automatically and will use it to load your schema!
130102

131103
Alternatively, you can define `parserOptions.schema` in the `*.graphql` override in your ESLint config.
132104

@@ -138,52 +110,52 @@ The parser allows you to specify a json file / graphql files(s) / url / raw stri
138110
"parser": "@graphql-eslint/eslint-plugin",
139111
"plugins": ["@graphql-eslint"],
140112
"rules": {
141-
"no-unused-types": ["error"]
113+
"@graphql-eslint/no-unreachable-types": "error"
142114
},
143115
+ "parserOptions": {
144116
+ "schema": "./schema.graphql"
145117
+ }
146118
}
147119
```
148120

149-
> You can find a complete [documentation of the `parserOptions` here](./docs/parser-options.md)
121+
> You can find a complete [documentation of the `parserOptions` here](docs/parser-options.md).
150122
151-
> Some rules requires type information to operate, it's marked in the docs for each rule!
123+
> Some rules require type information to operate, it's marked in the docs for each rule!
152124
153125
#### Extended linting rules with siblings operations
154126

155127
While implementing this tool, we had to find solutions for a better integration of the GraphQL ecosystem and ESLint core.
156128

157-
GraphQL operations can be distributed across many files, while ESLint operates on one file at a time. If you are using GraphQL fragments in separate files, some rules might yield incorrect results, due the the missing information.
129+
GraphQL operations can be distributed across many files, while ESLint operates on one file at a time. If you are using GraphQL fragments in separate files, some rules might yield incorrect results, due the missing information.
158130

159131
To workaround that, we allow you to provide additional information on your GraphQL operations, making it available for rules while doing the actual linting.
160132

161-
To provide that, we are using `@graphql-tools` loaders to load your sibling operations and fragments, just specify a glob expression(s) that points to your code/.graphql files:
133+
To provide that, we are using `graphql-tools` loaders to load your sibling operations and fragments, just specify a glob expression(s) that points to your code/`.graphql` files:
162134

163135
```diff
164136
{
165137
"files": ["*.graphql"],
166138
"parser": "@graphql-eslint/eslint-plugin",
167139
"plugins": ["@graphql-eslint"],
168140
"rules": {
169-
"unique-operation-name": ["error"]
141+
"@graphql-eslint/unique-operation-name": "error"
170142
},
171143
"parserOptions": {
172-
+ "operations": ["./src/**/*.graphql"],
144+
+ "operations": "./src/**/*.graphql",
173145
"schema": "./schema.graphql"
174146
}
175147
}
176148
```
177149

178150
### VSCode Integration
179151

180-
By default, [ESLint VSCode plugin](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) will not lint files with extensions other then js, jsx, ts, tsx.
152+
By default, [ESLint VSCode plugin](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) will not lint files with extensions other than `js`, `jsx`, `ts` and `tsx`.
181153

182154
In order to enable it processing other extensions, add the following section in `settings.json` or workspace configuration.
183155

184156
```json
185157
{
186-
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "graphql"],
158+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "graphql"]
187159
}
188160
```
189161

@@ -202,13 +174,13 @@ type Query {
202174
}
203175
```
204176

205-
You can also specify specific rules to disable, apply it over the entire file, `next-line` or (current) `line`.
177+
You can also specify specific rules to disable, apply it over the entire file, `eslint-disable-next-line` or current `eslint-disable-line`.
206178

207179
You can find a list of [ESLint directives here](https://eslint.org/docs/2.13.1/user-guide/configuring#disabling-rules-with-inline-comments).
208180

209181
## Available Rules
210182

211-
You can find a complete list of [all available rules here](./docs/README.md)
183+
You can find a complete list of [all available rules here](docs/README.md).
212184

213185
## Available Configs
214186

@@ -223,69 +195,60 @@ Enable it in your `.eslintrc` file with the `extends` option.
223195
"overrides": [
224196
{
225197
"files": ["*.js"],
226-
"processor": "@graphql-eslint/graphql",
227-
"rules": {
228-
// your rules for JavaScript files
229-
}
198+
"processor": "@graphql-eslint/graphql"
230199
},
231200
{
232201
"files": ["*.graphql"],
233202
- "parser": "@graphql-eslint/eslint-plugin",
234203
- "plugins": ["@graphql-eslint"],
235-
+ "extends": "plugin:@graphql-eslint/recommended", // or plugin:@graphql-eslint/all
236-
"rules": {
237-
// your rules for GraphQL files
238-
}
204+
+ "extends": "plugin:@graphql-eslint/recommended" // or plugin:@graphql-eslint/all
239205
}
240206
]
241207
}
242208
```
243209

244210
### `prettier` rule
245211

246-
The original `prettier` rule has been removed because `eslint-plugin-prettier` supports `.graphql` files well actually.
247-
248-
All you need to do is like the following for now:
212+
`eslint-plugin-prettier` supports `.graphql` files. You need to do the following:
249213

250214
```js
251-
// .eslintrc.js
252215
module.exports = {
253216
overrides: [
254217
{
255218
files: ['*.js'],
256219
processor: '@graphql-eslint/graphql',
257-
extends: ['plugin:prettier/recommended'],
220+
extends: ['plugin:prettier/recommended']
258221
},
259222
{
260223
files: ['*.graphql'],
261224
parser: '@graphql-eslint/eslint-plugin',
262225
plugins: ['@graphql-eslint'],
263226
rules: {
264-
'prettier/prettier': 'error',
265-
},
227+
'prettier/prettier': 'error'
228+
}
266229
},
267230
// the following is required for `eslint-plugin-prettier@<=3.4.0` temporarily
268231
// after https://github.com/prettier/eslint-plugin-prettier/pull/415
269232
// been merged and released, it can be deleted safely
270233
{
271234
files: ['*.js/*.graphql'],
272235
rules: {
273-
'prettier/prettier': 'off',
274-
},
275-
},
276-
],
277-
};
236+
'prettier/prettier': 'off'
237+
}
238+
}
239+
]
240+
}
278241
```
279242

280243
You can take [`examples/prettier`](examples/prettier/.eslintrc.js) as example.
281244

282-
It could be better to remove the unnecessary `*.js/*.graphql` overrides setting if <https://github.com/prettier/eslint-plugin-prettier/pull/415> will be merged and released.
245+
It could be better to remove the unnecessary `*.js/*.graphql` override setting if <https://github.com/prettier/eslint-plugin-prettier/pull/415> will be merged and released.
283246

284247
Please help to vote up if you want to speed up the progress.
285248

286249
## Further Reading
287250

288-
If you wish to learn more about this project, how the parser works, how to add custom rules and more, [please refer to the docs directory](./docs/README.md))
251+
If you wish to learn more about this project, how the parser works, how to add custom rules and more, [please refer to the docs directory](docs/README.md).
289252

290253
## Contributions
291254

@@ -295,8 +258,8 @@ And if this is your first time contributing to this project, please do read our
295258

296259
### Code of Conduct
297260

298-
Help us keep GraphQL ESLint open and inclusive. Please read and follow our [Code of Conduct](https://github.com/the-guild-org/Stack/blob/master/CODE_OF_CONDUCT.md) as adopted from [Contributor Covenant](https://www.contributor-covenant.org/)
261+
Help us keep GraphQL ESLint open and inclusive. Please read and follow our [Code of Conduct](https://github.com/the-guild-org/Stack/blob/master/CODE_OF_CONDUCT.md) as adopted from [Contributor Covenant](https://contributor-covenant.org).
299262

300263
## License
301264

302-
Released under the [MIT license](./LICENSE).
265+
Released under the [MIT license](LICENSE).

0 commit comments

Comments
 (0)