Skip to content

Commit bf475e8

Browse files
authored
[v4] rule changes (#1812)
1 parent f5cda6d commit bf475e8

Some content is hidden

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

51 files changed

+1062
-528
lines changed

.changeset/few-mails-sparkle.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': major
3+
---
4+
5+
- `alphabetize` rule changes
6+
7+
- add `definitions: true` option for `schema-all`/`operations-all` configs
8+
- rename `values: ['EnumTypeDefinition']` to `values: true`
9+
- rename `variables: ['OperationDefinition']` to `variables: true`
10+
- add `groups: ['id', '*', 'createdAt', 'updatedAt']` for `schema-all`/`operations-all` configs
11+
12+
- `require-id-when-available` rule changes
13+
14+
- rename rule to `require-selections`
15+
16+
- update `schema-all`/`operations-all` configs
17+
18+
- `require-description` rule changes
19+
20+
- add `rootField: true` option for `schema-recommended` config
21+
22+
- require `eslint` at least `>=8.44.0` as peerDependency
23+
24+
- `naming-convention`
25+
26+
- add new options for `schema-recommended` config
27+
28+
```json5
29+
{
30+
'EnumTypeDefinition,EnumTypeExtension': {
31+
forbiddenPrefixes: ['Enum'],
32+
forbiddenSuffixes: ['Enum']
33+
},
34+
'InterfaceTypeDefinition,InterfaceTypeExtension': {
35+
forbiddenPrefixes: ['Interface'],
36+
forbiddenSuffixes: ['Interface']
37+
},
38+
'UnionTypeDefinition,UnionTypeExtension': {
39+
forbiddenPrefixes: ['Union'],
40+
forbiddenSuffixes: ['Union']
41+
},
42+
'ObjectTypeDefinition,ObjectTypeExtension': {
43+
forbiddenPrefixes: ['Type'],
44+
forbiddenSuffixes: ['Type']
45+
}
46+
}
47+
```
48+
49+
- remove graphql-js' `unique-enum-value-names` rule
50+
51+
- rename `no-case-insensitive-enum-values-duplicates` to `unique-enum-value-names`
52+
53+
> Since this rule reports case-insensitive enum values duplicates too
54+
55+
- `require-nullable-result-in-root` rule changes
56+
57+
Do not check subscriptions

examples/multiple-projects-graphql-config/graphql.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { IGraphQLConfig } from 'graphql-config';
2-
import { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
1+
import type { IGraphQLConfig } from 'graphql-config';
2+
import type { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
33

44
const config: IGraphQLConfig = {
55
projects: {

examples/multiple-projects-graphql-config/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
},
1212
"devDependencies": {
1313
"@graphql-eslint/eslint-plugin": "workspace:*",
14-
"cosmiconfig-typescript-loader": "5.0.0",
15-
"eslint": "8.46.0",
16-
"ts-node": "10.9.1",
17-
"typescript": "5.1.6"
14+
"eslint": "8.46.0"
1815
}
1916
}

examples/programmatic/eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default [
2121
},
2222
},
2323
rules: {
24-
'@graphql-eslint/require-id-when-available': ['error', { fieldName: '_id' }],
24+
'@graphql-eslint/require-selections': ['error', { fieldName: '_id' }],
2525
'@graphql-eslint/unique-fragment-name': 'error',
2626
'@graphql-eslint/no-anonymous-operations': 'error',
2727
'@graphql-eslint/naming-convention': [
@@ -34,7 +34,7 @@ export default [
3434
},
3535
},
3636
],
37-
'@graphql-eslint/no-case-insensitive-enum-values-duplicates': ['error'],
37+
'@graphql-eslint/unique-enum-value-names': 'error',
3838
'@graphql-eslint/require-description': ['error', { FieldDefinition: true }],
3939
},
4040
},

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"generate:configs": "tsx scripts/generate-configs.ts",
1717
"lint": "eslint --ignore-path .gitignore --cache .",
1818
"lint:prettier": "prettier --cache --check .",
19-
"postinstall": "tsx scripts/patch-graphql.ts",
2019
"prebuild": "rimraf tsconfig.tsbuildinfo",
2120
"prerelease": "NODE_ENV=production pnpm build",
2221
"prettier": "pnpm lint:prettier --write",

packages/plugin/CHANGELOG.md

Lines changed: 93 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -552,29 +552,29 @@ Special thanks to @connorjs
552552

553553
### Before
554554

555-
```json
555+
```json5
556556
{
557-
"@graphql-eslint/avoid-operation-name-prefix": [
558-
"error",
557+
'@graphql-eslint/avoid-operation-name-prefix': [
558+
'error',
559559
{
560-
"keywords": ["Query", "Mutation", "Subscription", "Get"]
560+
keywords: ['Query', 'Mutation', 'Subscription', 'Get']
561561
}
562562
],
563-
"@graphql-eslint/no-operation-name-suffix": "error"
563+
'@graphql-eslint/no-operation-name-suffix': 'error'
564564
}
565565
```
566566

567567
### After
568568

569-
```json
569+
```json5
570570
{
571-
"@graphql-eslint/naming-convention": [
572-
"error",
571+
'@graphql-eslint/naming-convention': [
572+
'error',
573573
{
574-
"OperationDefinition": {
575-
"style": "PascalCase",
576-
"forbiddenPrefixes": ["Query", "Mutation", "Subscription", "Get"],
577-
"forbiddenSuffixes": ["Query", "Mutation", "Subscription"]
574+
OperationDefinition: {
575+
style: 'PascalCase',
576+
forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'],
577+
forbiddenSuffixes: ['Query', 'Mutation', 'Subscription']
578578
}
579579
}
580580
]
@@ -605,44 +605,44 @@ Special thanks to @connorjs
605605

606606
### Before
607607

608-
```json
608+
```json5
609609
{
610-
"@graphql-eslint/naming-convention": [
611-
"error",
610+
'@graphql-eslint/naming-convention': [
611+
'error',
612612
{
613-
"ObjectTypeDefinition": "PascalCase",
614-
"InterfaceTypeDefinition": "PascalCase",
615-
"EnumTypeDefinition": "PascalCase",
616-
"ScalarTypeDefinition": "PascalCase",
617-
"InputObjectTypeDefinition": "PascalCase",
618-
"UnionTypeDefinition": "PascalCase",
619-
"FieldDefinition": "camelCase",
620-
"InputValueDefinition": "camelCase",
621-
"QueryDefinition": {
622-
"forbiddenPrefixes": ["get"]
613+
ObjectTypeDefinition: 'PascalCase',
614+
InterfaceTypeDefinition: 'PascalCase',
615+
EnumTypeDefinition: 'PascalCase',
616+
ScalarTypeDefinition: 'PascalCase',
617+
InputObjectTypeDefinition: 'PascalCase',
618+
UnionTypeDefinition: 'PascalCase',
619+
FieldDefinition: 'camelCase',
620+
InputValueDefinition: 'camelCase',
621+
QueryDefinition: {
622+
forbiddenPrefixes: ['get']
623623
},
624-
"leadingUnderscore": "allow",
625-
"trailingUnderscore": "allow"
624+
leadingUnderscore: 'allow',
625+
trailingUnderscore: 'allow'
626626
}
627627
]
628628
}
629629
```
630630

631631
### After
632632

633-
```json
633+
```json5
634634
{
635-
"@graphql-eslint/naming-convention": [
636-
"error",
635+
'@graphql-eslint/naming-convention': [
636+
'error',
637637
{
638-
"types": "PascalCase",
639-
"FieldDefinition": "camelCase",
640-
"InputValueDefinition": "camelCase",
641-
"FieldDefinition[parent.name.value=Query]": {
642-
"forbiddenPrefixes": ["get"]
638+
types: 'PascalCase',
639+
FieldDefinition: 'camelCase',
640+
InputValueDefinition: 'camelCase',
641+
'FieldDefinition[parent.name.value=Query]': {
642+
forbiddenPrefixes: ['get']
643643
},
644-
"allowLeadingUnderscore": true,
645-
"allowTrailingUnderscore": true
644+
allowLeadingUnderscore: true,
645+
allowTrailingUnderscore: true
646646
}
647647
]
648648
}
@@ -663,21 +663,21 @@ Special thanks to @connorjs
663663

664664
### Before
665665

666-
```json
666+
```json5
667667
{
668-
"@graphql-eslint/require-description": [
669-
"error",
668+
'@graphql-eslint/require-description': [
669+
'error',
670670
{
671-
"on": [
672-
"ObjectTypeDefinition",
673-
"InterfaceTypeDefinition",
674-
"EnumTypeDefinition",
675-
"InputObjectTypeDefinition",
676-
"UnionTypeDefinition",
677-
"FieldDefinition",
678-
"InputValueDefinition",
679-
"EnumValueDefinition",
680-
"DirectiveDefinition"
671+
on: [
672+
'ObjectTypeDefinition',
673+
'InterfaceTypeDefinition',
674+
'EnumTypeDefinition',
675+
'InputObjectTypeDefinition',
676+
'UnionTypeDefinition',
677+
'FieldDefinition',
678+
'InputValueDefinition',
679+
'EnumValueDefinition',
680+
'DirectiveDefinition'
681681
]
682682
}
683683
]
@@ -686,16 +686,16 @@ Special thanks to @connorjs
686686

687687
### After
688688

689-
```json
689+
```json5
690690
{
691-
"@graphql-eslint/require-description": [
692-
"error",
691+
'@graphql-eslint/require-description': [
692+
'error',
693693
{
694-
"types": true,
695-
"FieldDefinition": true,
696-
"InputValueDefinition": true,
697-
"EnumValueDefinition": true,
698-
"DirectiveDefinition": true
694+
types: true,
695+
FieldDefinition: true,
696+
InputValueDefinition: true,
697+
EnumValueDefinition: true,
698+
DirectiveDefinition: true
699699
}
700700
]
701701
}
@@ -886,39 +886,41 @@ Special thanks to @connorjs
886886
As a drop-in replacement for the whole set of rules we had in `validate-against-schema`, you can
887887
use this:
888888

889-
```
890-
"@graphql-eslint/executable-definitions": "error",
891-
"@graphql-eslint/fields-on-correct-type": "error",
892-
"@graphql-eslint/fragments-on-composite-type": "error",
893-
"@graphql-eslint/known-argument-names": "error",
894-
"@graphql-eslint/known-directives": "error",
895-
"@graphql-eslint/known-fragment-names": "error",
896-
"@graphql-eslint/known-type-names": "error",
897-
"@graphql-eslint/lone-anonymous-operation": "error",
898-
"@graphql-eslint/lone-schema-definition": "error",
899-
"@graphql-eslint/no-fragment-cycles": "error",
900-
"@graphql-eslint/no-undefined-variables": "error",
901-
"@graphql-eslint/no-unused-fragments": "error",
902-
"@graphql-eslint/no-unused-variables": "error",
903-
"@graphql-eslint/overlapping-fields-can-be-merged": "error",
904-
"@graphql-eslint/possible-fragment-spread": "error",
905-
"@graphql-eslint/possible-type-extension": "error",
906-
"@graphql-eslint/provided-required-arguments": "error",
907-
"@graphql-eslint/scalar-leafs": "error",
908-
"@graphql-eslint/one-field-subscriptions": "error",
909-
"@graphql-eslint/unique-argument-names": "error",
910-
"@graphql-eslint/unique-directive-names": "error",
911-
"@graphql-eslint/unique-directive-names-per-location": "error",
912-
"@graphql-eslint/unique-enum-value-names": "error",
913-
"@graphql-eslint/unique-field-definition-names": "error",
914-
"@graphql-eslint/unique-input-field-names": "error",
915-
"@graphql-eslint/unique-operation-types": "error",
916-
"@graphql-eslint/unique-type-names": "error",
917-
"@graphql-eslint/unique-variable-names": "error",
918-
"@graphql-eslint/value-literals-of-correct-type": "error",
919-
"@graphql-eslint/variables-are-input-types": "error",
920-
"@graphql-eslint/variables-in-allowed-position": "error"
921-
```
889+
```json5
890+
{
891+
'@graphql-eslint/executable-definitions': 'error',
892+
'@graphql-eslint/fields-on-correct-type': 'error',
893+
'@graphql-eslint/fragments-on-composite-type': 'error',
894+
'@graphql-eslint/known-argument-names': 'error',
895+
'@graphql-eslint/known-directives': 'error',
896+
'@graphql-eslint/known-fragment-names': 'error',
897+
'@graphql-eslint/known-type-names': 'error',
898+
'@graphql-eslint/lone-anonymous-operation': 'error',
899+
'@graphql-eslint/lone-schema-definition': 'error',
900+
'@graphql-eslint/no-fragment-cycles': 'error',
901+
'@graphql-eslint/no-undefined-variables': 'error',
902+
'@graphql-eslint/no-unused-fragments': 'error',
903+
'@graphql-eslint/no-unused-variables': 'error',
904+
'@graphql-eslint/overlapping-fields-can-be-merged': 'error',
905+
'@graphql-eslint/possible-fragment-spread': 'error',
906+
'@graphql-eslint/possible-type-extension': 'error',
907+
'@graphql-eslint/provided-required-arguments': 'error',
908+
'@graphql-eslint/scalar-leafs': 'error',
909+
'@graphql-eslint/one-field-subscriptions': 'error',
910+
'@graphql-eslint/unique-argument-names': 'error',
911+
'@graphql-eslint/unique-directive-names': 'error',
912+
'@graphql-eslint/unique-directive-names-per-location': 'error',
913+
'@graphql-eslint/unique-enum-value-names': 'error',
914+
'@graphql-eslint/unique-field-definition-names': 'error',
915+
'@graphql-eslint/unique-input-field-names': 'error',
916+
'@graphql-eslint/unique-operation-types': 'error',
917+
'@graphql-eslint/unique-type-names': 'error',
918+
'@graphql-eslint/unique-variable-names': 'error',
919+
'@graphql-eslint/value-literals-of-correct-type': 'error',
920+
'@graphql-eslint/variables-are-input-types': 'error',
921+
'@graphql-eslint/variables-in-allowed-position': 'error'
922+
}
923+
```
922924

923925
- 61251e7: Bump dependencies and update minimum Node version to `v12`
924926

0 commit comments

Comments
 (0)