Skip to content

Commit

Permalink
chore: add tests for all examples (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri POSTOLOV committed Sep 20, 2021
1 parent daff904 commit 1dd2f43
Show file tree
Hide file tree
Showing 97 changed files with 1,492 additions and 541 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-news-jump.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

feat: add recommended and all configs
5 changes: 5 additions & 0 deletions .changeset/fifty-mayflies-notice.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

add new rule require-deprecation-date
5 changes: 5 additions & 0 deletions .changeset/rare-sheep-join.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

add new rule avoid-scalar-result-type-on-mutation
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -8,6 +8,7 @@ module.exports = {
'no-empty': 'off',
'no-console': 'error',
'no-prototype-builtins': 'off',
'no-restricted-globals': ['error', { name: 'isNaN', message: 'Use Number.isNaN instead' }],
'no-useless-constructor': 'off',
'no-unused-vars': 'off', // disable base rule as it can report incorrect errors
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
Expand All @@ -30,7 +31,7 @@ module.exports = {
extends: ['plugin:eslint-plugin/rules-recommended'],
rules: {
'eslint-plugin/no-deprecated-context-methods': 'error',
'eslint-plugin/require-meta-docs-description': ['error', { pattern: '.+\\.' }], // force to put a point at the end
'eslint-plugin/require-meta-docs-description': ['error', { pattern: '.+\\.$' }], // force to put a point at the end
'eslint-plugin/require-meta-docs-url': [
'error',
{ pattern: 'https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/{{name}}.md' },
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
@@ -0,0 +1 @@
node_modules/.bin/lint-staged
1 change: 1 addition & 0 deletions .husky/pre-push
@@ -0,0 +1 @@
yarn lint
10 changes: 1 addition & 9 deletions .prettierrc
Expand Up @@ -2,13 +2,5 @@
"trailingComma": "es5",
"printWidth": 120,
"singleQuote": true,
"arrowParens": "avoid",
"overrides": [
{
"files": "*.flow.js",
"options": {
"parser": "flow"
}
}
]
"arrowParens": "avoid"
}
56 changes: 38 additions & 18 deletions README.md
Expand Up @@ -32,22 +32,20 @@ This project integrates GraphQL and ESLint, for a better developer experience.

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

```
```sh
yarn add -D @graphql-eslint/eslint-plugin
```

Or, with NPM:

```
```sh
npm install --save-dev @graphql-eslint/eslint-plugin
```

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

> 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.
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):

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

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!
## Available Configs

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).

Enable it in your `.eslintrc` file with the `extends` option.

> 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.
```diff
{
"overrides": [
{
"files": ["*.js"],
"processor": "@graphql-eslint/graphql",
"rules": {
// your rules for JavaScript files
}
},
{
"files": ["*.graphql"],
- "parser": "@graphql-eslint/eslint-plugin",
- "plugins": ["@graphql-eslint"],
+ "extends": "plugin:@graphql-eslint/recommended", // or plugin:@graphql-eslint/all
"rules": {
// your rules for GraphQL files
}
}
]
}
```

### `prettier` rule

Expand All @@ -179,23 +206,16 @@ All you need to do is like the following for now:
module.exports = {
overrides: [
{
files: ['*.tsx', '*.ts', '*.jsx', '*.js'],
files: ['*.js'],
processor: '@graphql-eslint/graphql',
extends: ['plugin:prettier/recommended'],
},
{
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',
},
],
'prettier/prettier': 'error',
},
},
// the following is required for `eslint-plugin-prettier@<=3.4.0` temporarily
Expand All @@ -204,16 +224,16 @@ module.exports = {
{
files: ['*.js/*.graphql'],
rules: {
'prettier/prettier': 0
}
'prettier/prettier': 'off',
},
},
],
};
```

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.
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.

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

Expand Down

0 comments on commit 1dd2f43

Please sign in to comment.