Skip to content

Commit 982b5e4

Browse files
authored
feat!: update ESLint to flat config (#22)
1 parent 3e90b3d commit 982b5e4

File tree

10 files changed

+174
-146
lines changed

10 files changed

+174
-146
lines changed

.github/workflows/nodejs.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@ jobs:
1111
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
1212
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
1313
with:
14-
lint-eslint: false
15-
lint-prettier: false
16-
node-version-matrix: '[20]'
14+
node-version-matrix: '[22]'

.graphqlconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"schema": "./test/schema/**/*.graphql",
3-
"documents": "./test/operations/**/*.graphql"
2+
"schema": "./test/schema/**/*.{gql,graphql}",
3+
"documents": "./test/operations/**/*.{gql,graphql}"
44
}

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CHANGELOG.md

README.md

+31-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# eslint-config-graphql
1+
# @zakodium/eslint-config-graphql
22

3-
Shared ESLint config for frontend and backend projects using graphql
3+
Shared ESLint config for frontend and backend projects using GraphQL
44

55
## Installation
66

77
```console
8-
npx i -D @zakodium/eslint-config-graphql eslint
8+
npm i -D @zakodium/eslint-config-graphql eslint
99
```
1010

1111
`graphql` is also a peer dependency and would usually be in the dependencies of your project
@@ -16,27 +16,37 @@ npm i graphql
1616

1717
## Usage
1818

19-
Create a `.eslintrc.yml` with the following contents:
19+
Create a `eslint.config.mjs` with the following contents:
2020

21-
```yml
22-
extends: zakodium-graphql
23-
```
24-
25-
Create a `.graphqlrc` or `.graphqlconfig` file with your graphql configuration
26-
27-
Or alternatively, specify the options in the eslint config
21+
```js
22+
import graphql from '@zakodium/eslint-config-graphql';
2823

29-
```yml
30-
extends: zakodium-graphql
31-
overrides:
32-
files:
33-
- *.graphql
34-
parserOptions:
35-
schema: path/to/your/schema/**/*.graphql
36-
operations path/to/your/operations/**/*.graphql
24+
export default [
25+
// You will probably extend other configs as well.
26+
...graphql,
27+
];
28+
```
3729

30+
Create a `.graphqlrc` or `.graphqlconfig` file with your GraphQL configuration
31+
32+
Or alternatively, specify the options in the ESLint config:
33+
34+
```js
35+
import graphql from '@zakodium/eslint-config-graphql';
36+
37+
export default [
38+
// You will probably extend other configs as well.
39+
...graphql,
40+
{
41+
files: ['**/*.{gql,graphql}'],
42+
languageOptions: {
43+
parserOptions: {
44+
schema: 'path/to/your/schema/**/*.{gql,graphql}',
45+
operations: 'path/to/your/operations/**/*.{gql,graphql}',
46+
},
47+
},
48+
},
49+
];
3850
```
3951

4052
You can then customize the config for your project by changing rules in this file.
41-
42-

eslint.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cheminfo from 'eslint-config-cheminfo';
2+
3+
import graphql from './index.js';
4+
5+
export default [...cheminfo, ...graphql];

index.js

+96-92
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,104 @@
1-
module.exports = {
2-
overrides: [
3-
{
4-
files: ['*.graphql', '*.gql'],
5-
parser: '@graphql-eslint/eslint-plugin',
6-
plugins: ['@graphql-eslint'],
7-
rules: {
8-
'@graphql-eslint/alphabetize': 0,
9-
// Enforce all comments to be block comments
10-
'@graphql-eslint/description-style': 0,
11-
'@graphql-eslint/executable-definitions': 0,
12-
'@graphql-eslint/fields-on-correct-type': 2,
13-
'@graphql-eslint/fragments-on-composite-type': 2,
14-
// This rule is deactivated because it is not compatible with
15-
// naming input types PascalCase but mutations camelCase
16-
// https://github.com/dotansimha/graphql-eslint/blob/a2b71f6be17ff57614f57b3648ae2256cc834ea9/docs/rules/input-name.md
17-
'@graphql-eslint/input-name': 0,
18-
'@graphql-eslint/known-argument-names': 2,
19-
'@graphql-eslint/known-directives': 2,
20-
'@graphql-eslint/known-fragment-names': 2,
21-
'@graphql-eslint/known-type-names': 2,
22-
'@graphql-eslint/lone-anonymous-operation': 2,
23-
'@graphql-eslint/lone-schema-definition': 2,
24-
'@graphql-eslint/match-document-filename': 0,
25-
'@graphql-eslint/naming-convention': [
26-
'error',
27-
{
28-
ObjectTypeDefinition: 'PascalCase',
29-
FieldDefinition: 'camelCase',
30-
InputObjectTypeDefinition: 'PascalCase',
31-
InputValueDefinition: 'camelCase',
32-
EnumTypeDefinition: 'PascalCase',
33-
EnumValueDefinition: 'UPPER_CASE',
34-
InterfaceTypeDefinition: 'PascalCase',
35-
UnionTypeDefinition: 'PascalCase',
36-
ScalarTypeDefinition: 'PascalCase',
37-
OperationDefinition: 'PascalCase',
38-
Argument: 'camelCase',
39-
FragmentDefinition: 'camelCase',
40-
allowLeadingUnderscore: true,
41-
allowTrailingUnderscore: false,
42-
},
43-
],
1+
import * as graphqlEslint from '@graphql-eslint/eslint-plugin';
442

45-
'@graphql-eslint/no-anonymous-operations': 2,
46-
'@graphql-eslint/no-case-insensitive-enum-values-duplicates': 2,
47-
'@graphql-eslint/no-deprecated': 1,
48-
'@graphql-eslint/no-duplicate-fields': 2,
49-
'@graphql-eslint/no-hashtag-description': 2,
50-
'@graphql-eslint/no-fragment-cycles': 2,
51-
'@graphql-eslint/no-root-type': 0,
52-
// What errors does this rule prevent?
53-
'@graphql-eslint/no-scalar-result-type-on-mutation': 0,
54-
'@graphql-eslint/no-typename-prefix': 2,
55-
'@graphql-eslint/no-undefined-variables': 2,
56-
'@graphql-eslint/no-unreachable-types': 2,
57-
'@graphql-eslint/no-unused-fields': 1,
58-
'@graphql-eslint/no-unused-fragments': 2,
59-
'@graphql-eslint/no-unused-variables': 2,
3+
export default [
4+
{
5+
files: ['**/*.{gql,graphql}'],
6+
plugins: {
7+
'@graphql-eslint': graphqlEslint,
8+
},
9+
languageOptions: {
10+
parser: graphqlEslint,
11+
},
12+
rules: {
13+
'@graphql-eslint/alphabetize': 'off',
14+
// Enforce all comments to be block comments
15+
'@graphql-eslint/description-style': 'off',
16+
'@graphql-eslint/executable-definitions': 'off',
17+
'@graphql-eslint/fields-on-correct-type': 'error',
18+
'@graphql-eslint/fragments-on-composite-type': 'error',
19+
// This rule is deactivated because it is not compatible with
20+
// naming input types PascalCase but mutations camelCase
21+
// https://github.com/dotansimha/graphql-eslint/blob/a2b71f6be17ff57614f57b3648ae2256cc834ea9/docs/rules/input-name.md
22+
'@graphql-eslint/input-name': 'off',
23+
'@graphql-eslint/known-argument-names': 'error',
24+
'@graphql-eslint/known-directives': 'error',
25+
'@graphql-eslint/known-fragment-names': 'error',
26+
'@graphql-eslint/known-type-names': 'error',
27+
'@graphql-eslint/lone-anonymous-operation': 'error',
28+
'@graphql-eslint/lone-schema-definition': 'error',
29+
'@graphql-eslint/match-document-filename': 'off',
30+
'@graphql-eslint/naming-convention': [
31+
'error',
32+
{
33+
ObjectTypeDefinition: 'PascalCase',
34+
FieldDefinition: 'camelCase',
35+
InputObjectTypeDefinition: 'PascalCase',
36+
InputValueDefinition: 'camelCase',
37+
EnumTypeDefinition: 'PascalCase',
38+
EnumValueDefinition: 'UPPER_CASE',
39+
InterfaceTypeDefinition: 'PascalCase',
40+
UnionTypeDefinition: 'PascalCase',
41+
ScalarTypeDefinition: 'PascalCase',
42+
OperationDefinition: 'PascalCase',
43+
Argument: 'camelCase',
44+
FragmentDefinition: 'camelCase',
45+
allowLeadingUnderscore: true,
46+
allowTrailingUnderscore: false,
47+
},
48+
],
49+
50+
'@graphql-eslint/no-anonymous-operations': 'error',
51+
'@graphql-eslint/no-case-insensitive-enum-values-duplicates': 'error',
52+
'@graphql-eslint/no-deprecated': 'warn',
53+
'@graphql-eslint/no-duplicate-fields': 'error',
54+
'@graphql-eslint/no-hashtag-description': 'error',
55+
'@graphql-eslint/no-fragment-cycles': 'error',
56+
'@graphql-eslint/no-root-type': 'off',
57+
// What errors does this rule prevent?
58+
'@graphql-eslint/no-scalar-result-type-on-mutation': 'off',
59+
'@graphql-eslint/no-typename-prefix': 'error',
60+
'@graphql-eslint/no-undefined-variables': 'error',
61+
'@graphql-eslint/no-unreachable-types': 'error',
62+
'@graphql-eslint/no-unused-fields': 'warn',
63+
'@graphql-eslint/no-unused-fragments': 'error',
64+
'@graphql-eslint/no-unused-variables': 'error',
6065

61-
'@graphql-eslint/overlapping-fields-can-be-merged': 2,
62-
'@graphql-eslint/possible-fragment-spread': 2,
63-
'@graphql-eslint/possible-type-extension': 2,
64-
'@graphql-eslint/provided-required-arguments': 2,
66+
'@graphql-eslint/overlapping-fields-can-be-merged': 'error',
67+
'@graphql-eslint/possible-fragment-spread': 'error',
68+
'@graphql-eslint/possible-type-extension': 'error',
69+
'@graphql-eslint/provided-required-arguments': 'error',
6570

66-
'@graphql-eslint/relay-arguments': 0,
67-
'@graphql-eslint/relay-connection-types ': 0,
68-
'@graphql-eslint/relay-edge-types': 0,
69-
'@graphql-eslint/relay-page-info': 0,
71+
'@graphql-eslint/relay-arguments': 'off',
72+
'@graphql-eslint/relay-connection-types ': 'off',
73+
'@graphql-eslint/relay-edge-types': 'off',
74+
'@graphql-eslint/relay-page-info': 'off',
7075

71-
'@graphql-eslint/require-deprecation-date': 0,
72-
'@graphql-eslint/require-deprecation-reason': 2,
73-
'@graphql-eslint/require-description': 0,
74-
'@graphql-eslint/require-field-of-type-query-in-mutation-result': 0,
75-
'@graphql-eslint/require-id-when-available': 2,
76+
'@graphql-eslint/require-deprecation-date': 'off',
77+
'@graphql-eslint/require-deprecation-reason': 'error',
78+
'@graphql-eslint/require-description': 'off',
79+
'@graphql-eslint/require-field-of-type-query-in-mutation-result': 'off',
80+
'@graphql-eslint/require-id-when-available': 'error',
7681

77-
'@graphql-eslint/scalar-leafs': 2,
78-
'@graphql-eslint/selection-set-depth': 0,
79-
'@graphql-eslint/strict-id-in-types': 0,
82+
'@graphql-eslint/scalar-leafs': 'error',
83+
'@graphql-eslint/selection-set-depth': 'off',
84+
'@graphql-eslint/strict-id-in-types': 'off',
8085

81-
'@graphql-eslint/unique-argument-names': 2,
82-
'@graphql-eslint/unique-directive-names': 2,
83-
'@graphql-eslint/unique-directive-names-per-location': 2,
84-
'@graphql-eslint/unique-enum-value-names': 2,
85-
'@graphql-eslint/unique-field-definition-names': 2,
86-
'@graphql-eslint/unique-fragment-name': 2,
87-
'@graphql-eslint/unique-input-field-names': 2,
88-
'@graphql-eslint/unique-operation-name': 2,
89-
'@graphql-eslint/unique-operation-types': 2,
90-
'@graphql-eslint/unique-type-names': 2,
91-
'@graphql-eslint/unique-variable-names': 2,
86+
'@graphql-eslint/unique-argument-names': 'error',
87+
'@graphql-eslint/unique-directive-names': 'error',
88+
'@graphql-eslint/unique-directive-names-per-location': 'error',
89+
'@graphql-eslint/unique-enum-value-names': 'error',
90+
'@graphql-eslint/unique-field-definition-names': 'error',
91+
'@graphql-eslint/unique-fragment-name': 'error',
92+
'@graphql-eslint/unique-input-field-names': 'error',
93+
'@graphql-eslint/unique-operation-name': 'error',
94+
'@graphql-eslint/unique-operation-types': 'error',
95+
'@graphql-eslint/unique-type-names': 'error',
96+
'@graphql-eslint/unique-variable-names': 'error',
9297

93-
'@graphql-eslint/value-literals-of-correct-type': 2,
94-
'@graphql-eslint/variables-are-input-types': 2,
95-
'@graphql-eslint/variables-in-allowed-position': 2,
96-
strict: 0,
97-
},
98+
'@graphql-eslint/value-literals-of-correct-type': 'error',
99+
'@graphql-eslint/variables-are-input-types': 'error',
100+
'@graphql-eslint/variables-in-allowed-position': 'error',
101+
strict: 'off',
98102
},
99-
],
100-
};
103+
},
104+
];

package.json

+17-8
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,31 @@
22
"name": "@zakodium/eslint-config-graphql",
33
"version": "5.1.0",
44
"description": "ESLint config for GraphQL files",
5-
"main": "index.js",
5+
"type": "module",
6+
"exports": {
7+
".": "./index.js"
8+
},
69
"license": "MIT",
710
"repository": "https://github.com/zakodium/eslint-config-graphql",
811
"scripts": {
9-
"test": "npm run test-only",
10-
"test-only": "node test/test.mjs"
12+
"eslint": "eslint .",
13+
"eslint-fix": "npm run eslint -- --fix",
14+
"prettier": "prettier --check .",
15+
"prettier-write": "prettier --write .",
16+
"test": "npm run test-only && npm run eslint && npm run prettier",
17+
"test-only": "node test/test.js"
18+
},
19+
"dependencies": {
20+
"@graphql-eslint/eslint-plugin": "^3.20.1"
1121
},
1222
"peerDependencies": {
13-
"@graphql-eslint/eslint-plugin": "^3.20.1",
14-
"eslint": "^8.55.0",
23+
"eslint": "^8.57.0",
1524
"graphql": "^16.8.1"
1625
},
1726
"devDependencies": {
18-
"@graphql-eslint/eslint-plugin": "3.20.1",
19-
"eslint": "8.55.0",
27+
"eslint": "8.57.0",
28+
"eslint-config-cheminfo": "^11.0.3",
2029
"graphql": "16.8.1",
21-
"prettier": "^3.1.0"
30+
"prettier": "^3.3.2"
2231
}
2332
}
File renamed without changes.

test/test.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import assert from 'node:assert';
2+
3+
import { loadESLint } from 'eslint';
4+
5+
const ESLint = await loadESLint({ useFlatConfig: true });
6+
const eslint = new ESLint();
7+
const formatter = await eslint.loadFormatter('stylish');
8+
9+
const result = await eslint.lintFiles(['test/**/*.{gql,graphql}']);
10+
11+
assert.strictEqual(result.length, 3, '3 graphql files should be linted');
12+
13+
const errorCount = result.reduce(
14+
(prev, current) => prev + current.errorCount,
15+
0,
16+
);
17+
assert.strictEqual(
18+
errorCount,
19+
0,
20+
`graphql files should not have any errors: ${formatter.format(result)}`,
21+
);

test/test.mjs

-20
This file was deleted.

0 commit comments

Comments
 (0)