Skip to content

Commit

Permalink
feat: remove prettier rule, add related docs (#397)
Browse files Browse the repository at this point in the history
* feat: remove `prettier` rule, add related docs

* docs: add changeset for the feat change
  • Loading branch information
JounQin committed May 18, 2021
1 parent 7598f5f commit 14211d6
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 456 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-foxes-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-eslint/eslint-plugin": minor
---

feat: remove `prettier` rule, add related docs
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,55 @@ You can find a complete list of [all available rules here](./docs/README.md)

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

The original `prettier` rule has been removed because `eslint-plugin-prettier` supports `.graphql` files well actually.

All you need to do is like the following for now:

```js
// .eslintrc.js
module.exports = {
overrides: [
{
files: ['*.tsx', '*.ts', '*.jsx', '*.js'],
processor: '@graphql-eslint/graphql',
},
{
files: ['*.graphql'],
parser: '@graphql-eslint/eslint-plugin',
plugins: ['@graphql-eslint'],
// the following is required for `eslint-plugin-prettier@<=3.4.0` temporarily
// after https://github.com/prettier/eslint-plugin-prettier/pull/413
// been merged and released, it can be deleted safely
rules: {
'prettier/prettier': [
2,
{
parser: 'graphql',
},
],
},
},
// the following is required for `eslint-plugin-prettier@<=3.4.0` temporarily
// after https://github.com/prettier/eslint-plugin-prettier/pull/415
// been merged and released, it can be deleted safely
{
files: ['*.js/*.graphql'],
rules: {
'prettier/prettier': 0
}
},
],
};
```

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

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.

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

## Further Reading

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))
Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
- [`naming-convention`](./rules/naming-convention.md)
- [`input-name`](./rules/input-name.md)
- [`strict-id-in-types`](./rules/strict-id-in-types.md)
- [`prettier`](./rules/prettier.md)
- [`executable-definitions`](./rules/executable-definitions.md)
- [`fields-on-correct-type`](./rules/fields-on-correct-type.md)
- [`fragments-on-composite-type`](./rules/fragments-on-composite-type.md)
Expand Down
16 changes: 0 additions & 16 deletions docs/rules/prettier.md

This file was deleted.

6 changes: 3 additions & 3 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"lint": "eslint --ext graphql,js ."
},
"dependencies": {
"eslint": "7.14.0",
"eslint": "7.24.0",
"@graphql-eslint/eslint-plugin": "0.9.1",
"graphql": "15.4.0",
"typescript": "4.1.2"
"graphql": "15.5.0",
"typescript": "4.1.5"
}
}
6 changes: 3 additions & 3 deletions examples/code-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"lint": "eslint --ext graphql,js ."
},
"dependencies": {
"eslint": "7.14.0",
"eslint": "7.24.0",
"@graphql-eslint/eslint-plugin": "0.9.1",
"graphql": "15.4.0",
"typescript": "4.1.2"
"graphql": "15.5.0",
"typescript": "4.1.5"
}
}
6 changes: 3 additions & 3 deletions examples/graphql-config-code-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
},
"dependencies": {
"@graphql-eslint/eslint-plugin": "0.9.1",
"eslint": "7.14.0",
"graphql": "15.4.0",
"eslint": "7.24.0",
"graphql": "15.5.0",
"graphql-tag": "^2.11.0",
"typescript": "4.1.2"
"typescript": "4.1.5"
}
}
6 changes: 3 additions & 3 deletions examples/graphql-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
},
"dependencies": {
"graphql-config": "3.2.0",
"eslint": "7.14.0",
"eslint": "7.24.0",
"@graphql-eslint/eslint-plugin": "0.9.1",
"graphql": "15.4.0",
"typescript": "4.1.2"
"graphql": "15.5.0",
"typescript": "4.1.5"
}
}
34 changes: 34 additions & 0 deletions examples/prettier/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
extends: ['plugin:prettier/recommended'],
overrides: [
{
files: ['*.tsx', '*.ts', '*.jsx', '*.js'],
processor: '@graphql-eslint/graphql',
},
{
files: ['*.graphql'],
parser: '@graphql-eslint/eslint-plugin',
plugins: ['@graphql-eslint'],
// the following is required for `eslint-plugin-prettier@<=3.4.0` temporarily
// after https://github.com/prettier/eslint-plugin-prettier/pull/413
// been merged and released, it can be deleted safely
rules: {
'prettier/prettier': [
2,
{
parser: 'graphql',
},
],
},
},
// the following is required for `eslint-plugin-prettier@<=3.4.0` temporarily
// after https://github.com/prettier/eslint-plugin-prettier/pull/415
// been merged and released, it can be deleted safely
{
files: ['*.js/*.graphql'],
rules: {
'prettier/prettier': 0,
},
},
],
};
16 changes: 16 additions & 0 deletions examples/prettier/invalid.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
query GetUser($userId: ID!) {
user(id: $userId) {
id,
name,
isViewerFriend,
profilePicture(size: 50) {
...PictureFragment
}
}
}

fragment PictureFragment on Picture {
uri,
width,
height
}
17 changes: 17 additions & 0 deletions examples/prettier/invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const quqery = /* GraphQL */ `query GetUser($userId: ID!) {
user(id: $userId) {
id,
name,
isViewerFriend,
profilePicture(size: 50) {
...PictureFragment
}
}
}
fragment PictureFragment on Picture {
uri,
width,
height
}
`
21 changes: 21 additions & 0 deletions examples/prettier/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@graphql-eslint/example-prettier",
"private": true,
"version": "0.0.1",
"repository": "https://github.com/dotansimha/graphql-eslint",
"author": "JounQin <admin@1stg.me>",
"license": "MIT",
"scripts": {
"lint": "eslint --ext graphql,js ."
},
"dependencies": {
"eslint": "7.24.0",
"eslint-config-prettier": "8.2.0",
"eslint-plugin-prettier": "3.4.0",
"@graphql-eslint/eslint-plugin": "0.9.1",
"graphql": "15.5.0",
"prettier": "1.19.1",
"typescript": "4.1.5"
}
}

1 change: 1 addition & 0 deletions examples/prettier/valid.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalar Test
3 changes: 3 additions & 0 deletions examples/prettier/valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const content = /* GraphQL */ `
scalar Test
`;
1 change: 0 additions & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"prepack": "bob prepack"
},
"dependencies": {
"prettier-linter-helpers": "1.0.0",
"@graphql-tools/utils": "~7.8.0",
"@graphql-tools/load": "~6.2.0",
"@graphql-tools/graphql-file-loader": "~6.2.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/plugin/src/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import noCaseInsensitiveEnumValuesDuplicates from './no-case-insensitive-enum-va
import requireDescription from './require-description';
import requireIdWhenAvailable from './require-id-when-available';
import descriptionStyle from './description-style';
import prettier from './prettier';
import namingConvention from './naming-convention';
import inputName from './input-name';
import uniqueFragmentName from './unique-fragment-name';
Expand Down Expand Up @@ -41,6 +40,5 @@ export const rules: Record<string, GraphQLESLintRule> = {
'naming-convention': namingConvention,
'input-name': inputName,
'strict-id-in-types': strictIdInTypes,
prettier,
...GRAPHQL_JS_VALIDATIONS,
};

0 comments on commit 14211d6

Please sign in to comment.