Skip to content

Commit 1dd2f43

Browse files
author
Dimitri POSTOLOV
authored
chore: add tests for all examples (#635)
1 parent daff904 commit 1dd2f43

File tree

97 files changed

+1492
-541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1492
-541
lines changed

.changeset/curly-news-jump.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+
feat: add recommended and all configs

.changeset/fifty-mayflies-notice.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+
add new rule require-deprecation-date

.changeset/rare-sheep-join.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+
add new rule avoid-scalar-result-type-on-mutation

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
'no-empty': 'off',
99
'no-console': 'error',
1010
'no-prototype-builtins': 'off',
11+
'no-restricted-globals': ['error', { name: 'isNaN', message: 'Use Number.isNaN instead' }],
1112
'no-useless-constructor': 'off',
1213
'no-unused-vars': 'off', // disable base rule as it can report incorrect errors
1314
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
@@ -30,7 +31,7 @@ module.exports = {
3031
extends: ['plugin:eslint-plugin/rules-recommended'],
3132
rules: {
3233
'eslint-plugin/no-deprecated-context-methods': 'error',
33-
'eslint-plugin/require-meta-docs-description': ['error', { pattern: '.+\\.' }], // force to put a point at the end
34+
'eslint-plugin/require-meta-docs-description': ['error', { pattern: '.+\\.$' }], // force to put a point at the end
3435
'eslint-plugin/require-meta-docs-url': [
3536
'error',
3637
{ pattern: 'https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/{{name}}.md' },

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/.bin/lint-staged

.husky/pre-push

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn lint

.prettierrc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,5 @@
22
"trailingComma": "es5",
33
"printWidth": 120,
44
"singleQuote": true,
5-
"arrowParens": "avoid",
6-
"overrides": [
7-
{
8-
"files": "*.flow.js",
9-
"options": {
10-
"parser": "flow"
11-
}
12-
}
13-
]
5+
"arrowParens": "avoid"
146
}

README.md

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,20 @@ This project integrates GraphQL and ESLint, for a better developer experience.
3232

3333
Start by installing the plugin package, which includes everything you need:
3434

35-
```
35+
```sh
3636
yarn add -D @graphql-eslint/eslint-plugin
3737
```
3838

3939
Or, with NPM:
4040

41-
```
41+
```sh
4242
npm install --save-dev @graphql-eslint/eslint-plugin
4343
```
4444

4545
> Also, make sure you have `graphql` dependency in your project.
4646
4747
### Configuration
4848

49-
> Note: This plugin doesn't activate any rule by default at the moment, we are currently thinking of the right rules to be the "recommended" and the default set. Until then, please make sure to active rules based on your needs.
50-
5149
To get started, create an override configuration for your ESLint, while applying it to to `.graphql` files (do that even if you are declaring your operations in code files):
5250

5351
```json
@@ -166,7 +164,36 @@ You can find a list of [ESLint directives here](https://eslint.org/docs/2.13.1/u
166164

167165
You can find a complete list of [all available rules here](./docs/README.md)
168166

169-
> This repo doesn't exports a "recommended" set of rules - feel free to recommend us!
167+
## Available Configs
168+
169+
This plugin exports a [`recommended` config](packages/plugin/src/configs/recommended.ts) that enforces good practices and an [`all` config](packages/plugin/src/configs/all.ts) that makes use of all rules (except for deprecated ones).
170+
171+
Enable it in your `.eslintrc` file with the `extends` option.
172+
173+
> These configs under the hood set `parser` as `@graphql-eslint/eslint-plugin` and add `@graphql-eslint` to `plugins` array, so you don't need to specify them.
174+
175+
```diff
176+
{
177+
"overrides": [
178+
{
179+
"files": ["*.js"],
180+
"processor": "@graphql-eslint/graphql",
181+
"rules": {
182+
// your rules for JavaScript files
183+
}
184+
},
185+
{
186+
"files": ["*.graphql"],
187+
- "parser": "@graphql-eslint/eslint-plugin",
188+
- "plugins": ["@graphql-eslint"],
189+
+ "extends": "plugin:@graphql-eslint/recommended", // or plugin:@graphql-eslint/all
190+
"rules": {
191+
// your rules for GraphQL files
192+
}
193+
}
194+
]
195+
}
196+
```
170197

171198
### `prettier` rule
172199

@@ -179,23 +206,16 @@ All you need to do is like the following for now:
179206
module.exports = {
180207
overrides: [
181208
{
182-
files: ['*.tsx', '*.ts', '*.jsx', '*.js'],
209+
files: ['*.js'],
183210
processor: '@graphql-eslint/graphql',
211+
extends: ['plugin:prettier/recommended'],
184212
},
185213
{
186214
files: ['*.graphql'],
187215
parser: '@graphql-eslint/eslint-plugin',
188216
plugins: ['@graphql-eslint'],
189-
// the following is required for `eslint-plugin-prettier@<=3.4.0` temporarily
190-
// after https://github.com/prettier/eslint-plugin-prettier/pull/413
191-
// been merged and released, it can be deleted safely
192217
rules: {
193-
'prettier/prettier': [
194-
2,
195-
{
196-
parser: 'graphql',
197-
},
198-
],
218+
'prettier/prettier': 'error',
199219
},
200220
},
201221
// the following is required for `eslint-plugin-prettier@<=3.4.0` temporarily
@@ -204,16 +224,16 @@ module.exports = {
204224
{
205225
files: ['*.js/*.graphql'],
206226
rules: {
207-
'prettier/prettier': 0
208-
}
227+
'prettier/prettier': 'off',
228+
},
209229
},
210230
],
211231
};
212232
```
213233

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

216-
It could be better to remove the unnecessary parser setting if https://github.com/prettier/eslint-plugin-prettier/pull/413 and https://github.com/prettier/eslint-plugin-prettier/pull/415 been merged and released.
236+
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.
217237

218238
Please help to vote up if you want to speed up the progress.
219239

0 commit comments

Comments
 (0)