@graphql-eslint/eslint-plugin 3.0.0-alpha-698204a.0 → 3.0.0-alpha-2918431.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configs/index.d.ts +24 -30
- package/configs/operations-recommended.d.ts +11 -13
- package/configs/schema-all.d.ts +1 -3
- package/configs/schema-recommended.d.ts +12 -14
- package/docs/README.md +1 -1
- package/docs/rules/description-style.md +1 -1
- package/docs/rules/naming-convention.md +138 -38
- package/docs/rules/no-root-type.md +3 -14
- package/docs/rules/require-description.md +35 -21
- package/index.js +103 -127
- package/index.mjs +103 -127
- package/package.json +1 -1
- package/rules/index.d.ts +110 -112
- package/rules/naming-convention.d.ts +2 -3
- package/rules/no-root-type.d.ts +1 -1
- package/rules/require-description.d.ts +2 -3
package/index.js
CHANGED
@@ -39,20 +39,18 @@ const schemaRecommendedConfig = {
|
|
39
39
|
{
|
40
40
|
types: 'PascalCase',
|
41
41
|
fields: 'camelCase',
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
'
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
'
|
53
|
-
|
54
|
-
forbiddenSuffixes: ['Subscription'],
|
55
|
-
},
|
42
|
+
EnumValueDefinition: 'UPPER_CASE',
|
43
|
+
'FieldDefinition[parent.name.value=Query]': {
|
44
|
+
forbiddenPrefixes: ['query', 'get'],
|
45
|
+
forbiddenSuffixes: ['Query'],
|
46
|
+
},
|
47
|
+
'FieldDefinition[parent.name.value=Mutation]': {
|
48
|
+
forbiddenPrefixes: ['mutation'],
|
49
|
+
forbiddenSuffixes: ['Mutation'],
|
50
|
+
},
|
51
|
+
'FieldDefinition[parent.name.value=Subscription]': {
|
52
|
+
forbiddenPrefixes: ['subscription'],
|
53
|
+
forbiddenSuffixes: ['Subscription'],
|
56
54
|
},
|
57
55
|
},
|
58
56
|
],
|
@@ -92,7 +90,7 @@ const schemaAllConfig = {
|
|
92
90
|
'@graphql-eslint/no-scalar-result-type-on-mutation': 'error',
|
93
91
|
'@graphql-eslint/no-unused-fields': 'off',
|
94
92
|
'@graphql-eslint/require-deprecation-date': 'error',
|
95
|
-
'@graphql-eslint/require-description': ['error', { types: true,
|
93
|
+
'@graphql-eslint/require-description': ['error', { types: true, DirectiveDefinition: true }],
|
96
94
|
'@graphql-eslint/require-field-of-type-query-in-mutation-result': 'error',
|
97
95
|
},
|
98
96
|
};
|
@@ -114,16 +112,14 @@ const operationsRecommendedConfig = {
|
|
114
112
|
'@graphql-eslint/naming-convention': [
|
115
113
|
'error',
|
116
114
|
{
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
FragmentDefinition: { style: 'PascalCase', forbiddenPrefixes: ['Fragment'], forbiddenSuffixes: ['Fragment'] },
|
126
|
-
},
|
115
|
+
Argument: 'camelCase',
|
116
|
+
VariableDefinition: 'camelCase',
|
117
|
+
OperationDefinition: {
|
118
|
+
style: 'PascalCase',
|
119
|
+
forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'],
|
120
|
+
forbiddenSuffixes: ['Query', 'Mutation', 'Subscription'],
|
121
|
+
},
|
122
|
+
FragmentDefinition: { style: 'PascalCase', forbiddenPrefixes: ['Fragment'], forbiddenSuffixes: ['Fragment'] },
|
127
123
|
},
|
128
124
|
],
|
129
125
|
'@graphql-eslint/no-anonymous-operations': 'error',
|
@@ -912,23 +908,21 @@ const rule$1 = {
|
|
912
908
|
properties: {
|
913
909
|
style: {
|
914
910
|
enum: ['block', 'inline'],
|
915
|
-
default: '
|
911
|
+
default: 'block',
|
916
912
|
},
|
917
913
|
},
|
918
914
|
},
|
919
915
|
],
|
920
916
|
},
|
921
917
|
create(context) {
|
922
|
-
const { style } = context.options[0] || {
|
923
|
-
const
|
918
|
+
const { style = 'block' } = context.options[0] || {};
|
919
|
+
const isBlock = style === 'block';
|
924
920
|
return {
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
});
|
931
|
-
}
|
921
|
+
[`.description[type=StringValue][block!=${isBlock}]`](node) {
|
922
|
+
context.report({
|
923
|
+
loc: getLocation(node.loc),
|
924
|
+
message: `Unexpected ${isBlock ? 'inline' : 'block'} description`,
|
925
|
+
});
|
932
926
|
},
|
933
927
|
};
|
934
928
|
},
|
@@ -1318,38 +1312,34 @@ const rule$4 = {
|
|
1318
1312
|
{
|
1319
1313
|
types: 'PascalCase',
|
1320
1314
|
fields: 'camelCase',
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
'
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
'
|
1332
|
-
|
1333
|
-
forbiddenSuffixes: ['Subscription'],
|
1334
|
-
},
|
1315
|
+
EnumValueDefinition: 'UPPER_CASE',
|
1316
|
+
'FieldDefinition[parent.name.value=Query]': {
|
1317
|
+
forbiddenPrefixes: ['query', 'get'],
|
1318
|
+
forbiddenSuffixes: ['Query'],
|
1319
|
+
},
|
1320
|
+
'FieldDefinition[parent.name.value=Mutation]': {
|
1321
|
+
forbiddenPrefixes: ['mutation'],
|
1322
|
+
forbiddenSuffixes: ['Mutation'],
|
1323
|
+
},
|
1324
|
+
'FieldDefinition[parent.name.value=Subscription]': {
|
1325
|
+
forbiddenPrefixes: ['subscription'],
|
1326
|
+
forbiddenSuffixes: ['Subscription'],
|
1335
1327
|
},
|
1336
1328
|
},
|
1337
1329
|
],
|
1338
1330
|
operations: [
|
1339
1331
|
{
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
forbiddenSuffixes: ['Fragment'],
|
1352
|
-
},
|
1332
|
+
Argument: 'camelCase',
|
1333
|
+
VariableDefinition: 'camelCase',
|
1334
|
+
OperationDefinition: {
|
1335
|
+
style: 'PascalCase',
|
1336
|
+
forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'],
|
1337
|
+
forbiddenSuffixes: ['Query', 'Mutation', 'Subscription'],
|
1338
|
+
},
|
1339
|
+
FragmentDefinition: {
|
1340
|
+
style: 'PascalCase',
|
1341
|
+
forbiddenPrefixes: ['Fragment'],
|
1342
|
+
forbiddenSuffixes: ['Fragment'],
|
1353
1343
|
},
|
1354
1344
|
},
|
1355
1345
|
],
|
@@ -1389,14 +1379,6 @@ const rule$4 = {
|
|
1389
1379
|
type: 'object',
|
1390
1380
|
additionalProperties: false,
|
1391
1381
|
properties: {
|
1392
|
-
types: {
|
1393
|
-
...schemaOption$1,
|
1394
|
-
description: `Includes:\n\n${TYPES_KINDS.map(kind => `- [${kind}](https://spec.graphql.org/October2021/#${kind})`).join('\n')}`,
|
1395
|
-
},
|
1396
|
-
fields: {
|
1397
|
-
...schemaOption$1,
|
1398
|
-
description: `Includes:\n\n${FIELDS_KINDS.map(kind => `- [${kind}](https://spec.graphql.org/October2021/#${kind})`).join('\n')}`,
|
1399
|
-
},
|
1400
1382
|
allowLeadingUnderscore: {
|
1401
1383
|
type: 'boolean',
|
1402
1384
|
default: false,
|
@@ -1405,35 +1387,42 @@ const rule$4 = {
|
|
1405
1387
|
type: 'boolean',
|
1406
1388
|
default: false,
|
1407
1389
|
},
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
description: [
|
1412
|
-
'May contain the following `ASTNode` names:',
|
1413
|
-
'',
|
1414
|
-
...ALLOWED_KINDS.map(kind => `- [${kind}](https://spec.graphql.org/October2021/#${kind})`),
|
1415
|
-
'',
|
1416
|
-
"> It's also possible to use a [`selector`](https://eslint.org/docs/developer-guide/selectors) that starts with `ASTNode` name",
|
1417
|
-
'>',
|
1418
|
-
'> Example: pattern property `FieldDefinition[parent.name.value=Query]` will match only fields for type `Query`',
|
1419
|
-
].join('\n'),
|
1420
|
-
patternProperties: {
|
1421
|
-
[`^(${ALLOWED_KINDS.join('|')})(.+)?$`]: schemaOption$1,
|
1422
|
-
},
|
1390
|
+
types: {
|
1391
|
+
...schemaOption$1,
|
1392
|
+
description: `Includes:\n\n${TYPES_KINDS.map(kind => `- \`${kind}\``).join('\n')}`,
|
1423
1393
|
},
|
1424
|
-
|
1394
|
+
fields: {
|
1395
|
+
...schemaOption$1,
|
1396
|
+
description: `Includes:\n\n${FIELDS_KINDS.map(kind => `- \`${kind}\``).join('\n')}`,
|
1397
|
+
},
|
1398
|
+
...Object.fromEntries(ALLOWED_KINDS.map(kind => [
|
1399
|
+
kind,
|
1400
|
+
{
|
1401
|
+
...schemaOption$1,
|
1402
|
+
description: `Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`,
|
1403
|
+
},
|
1404
|
+
])),
|
1405
|
+
},
|
1406
|
+
patternProperties: {
|
1407
|
+
[`^(${ALLOWED_KINDS.join('|')})(.+)?$`]: schemaOption$1,
|
1408
|
+
},
|
1409
|
+
description: [
|
1410
|
+
"> It's possible to use a [`selector`](https://eslint.org/docs/developer-guide/selectors) that starts with allowed `ASTNode` names which are described below.",
|
1411
|
+
'>',
|
1412
|
+
'> Paste or drop code into the editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your selector.',
|
1413
|
+
'>',
|
1414
|
+
'> Example: pattern property `FieldDefinition[parent.name.value=Query]` will match only fields for type `Query`.',
|
1415
|
+
].join('\n'),
|
1425
1416
|
},
|
1426
1417
|
},
|
1427
1418
|
},
|
1428
1419
|
create(context) {
|
1429
|
-
const options = {
|
1430
|
-
|
1431
|
-
...context.options[0],
|
1432
|
-
};
|
1420
|
+
const options = context.options[0] || {};
|
1421
|
+
const { allowLeadingUnderscore, allowTrailingUnderscore, types, fields, ...restOptions } = options;
|
1433
1422
|
function normalisePropertyOption(kind) {
|
1434
|
-
let style = options
|
1423
|
+
let style = options[kind];
|
1435
1424
|
if (!style) {
|
1436
|
-
style = TYPES_KINDS.includes(kind) ?
|
1425
|
+
style = TYPES_KINDS.includes(kind) ? types : fields;
|
1437
1426
|
}
|
1438
1427
|
return typeof style === 'object' ? style : { style };
|
1439
1428
|
}
|
@@ -1454,10 +1443,10 @@ const rule$4 = {
|
|
1454
1443
|
}
|
1455
1444
|
function getErrorMessage() {
|
1456
1445
|
let name = nodeName;
|
1457
|
-
if (
|
1446
|
+
if (allowLeadingUnderscore) {
|
1458
1447
|
name = name.replace(/^_*/, '');
|
1459
1448
|
}
|
1460
|
-
if (
|
1449
|
+
if (allowTrailingUnderscore) {
|
1461
1450
|
name = name.replace(/_*$/, '');
|
1462
1451
|
}
|
1463
1452
|
if (prefix && !name.startsWith(prefix)) {
|
@@ -1491,15 +1480,13 @@ const rule$4 = {
|
|
1491
1480
|
});
|
1492
1481
|
};
|
1493
1482
|
const listeners = {};
|
1494
|
-
if (!
|
1483
|
+
if (!allowLeadingUnderscore) {
|
1495
1484
|
listeners['Name[value=/^_/]:matches([parent.kind!=Field], [parent.kind=Field][parent.alias])'] = checkUnderscore;
|
1496
1485
|
}
|
1497
|
-
if (!
|
1486
|
+
if (!allowTrailingUnderscore) {
|
1498
1487
|
listeners['Name[value=/_$/]:matches([parent.kind!=Field], [parent.kind=Field][parent.alias])'] = checkUnderscore;
|
1499
1488
|
}
|
1500
|
-
const selectors = new Set([
|
1501
|
-
.flat()
|
1502
|
-
.filter(Boolean));
|
1489
|
+
const selectors = new Set([types && TYPES_KINDS, fields && FIELDS_KINDS, Object.keys(restOptions)].flat().filter(Boolean));
|
1503
1490
|
for (const selector of selectors) {
|
1504
1491
|
listeners[selector] = checkNode(selector);
|
1505
1492
|
}
|
@@ -1904,18 +1891,18 @@ const rule$9 = {
|
|
1904
1891
|
},
|
1905
1892
|
};
|
1906
1893
|
|
1907
|
-
const ROOT_TYPES = ['
|
1894
|
+
const ROOT_TYPES = ['mutation', 'subscription'];
|
1908
1895
|
const rule$a = {
|
1909
1896
|
meta: {
|
1910
1897
|
type: 'suggestion',
|
1911
1898
|
docs: {
|
1912
1899
|
category: 'Schema',
|
1913
|
-
description: 'Disallow using root types
|
1900
|
+
description: 'Disallow using root types `mutation` and/or `subscription`.',
|
1914
1901
|
url: 'https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/no-root-type.md',
|
1915
1902
|
requiresSchema: true,
|
1916
1903
|
examples: [
|
1917
1904
|
{
|
1918
|
-
title: 'Incorrect
|
1905
|
+
title: 'Incorrect',
|
1919
1906
|
usage: [{ disallow: ['mutation', 'subscription'] }],
|
1920
1907
|
code: /* GraphQL */ `
|
1921
1908
|
type Mutation {
|
@@ -1924,16 +1911,7 @@ const rule$a = {
|
|
1924
1911
|
`,
|
1925
1912
|
},
|
1926
1913
|
{
|
1927
|
-
title: '
|
1928
|
-
usage: [{ disallow: ['query'] }],
|
1929
|
-
code: /* GraphQL */ `
|
1930
|
-
type Query {
|
1931
|
-
users: [User!]!
|
1932
|
-
}
|
1933
|
-
`,
|
1934
|
-
},
|
1935
|
-
{
|
1936
|
-
title: 'Correct (`read-only` schema)',
|
1914
|
+
title: 'Correct',
|
1937
1915
|
usage: [{ disallow: ['mutation', 'subscription'] }],
|
1938
1916
|
code: /* GraphQL */ `
|
1939
1917
|
type Query {
|
@@ -1968,7 +1946,6 @@ const rule$a = {
|
|
1968
1946
|
const schema = requireGraphQLSchemaFromContext('no-root-type', context);
|
1969
1947
|
const disallow = new Set(context.options[0].disallow);
|
1970
1948
|
const rootTypeNames = [
|
1971
|
-
disallow.has('query') && schema.getQueryType(),
|
1972
1949
|
disallow.has('mutation') && schema.getMutationType(),
|
1973
1950
|
disallow.has('subscription') && schema.getSubscriptionType(),
|
1974
1951
|
]
|
@@ -2548,7 +2525,7 @@ const rule$h = {
|
|
2548
2525
|
examples: [
|
2549
2526
|
{
|
2550
2527
|
title: 'Incorrect',
|
2551
|
-
usage: [{ types: true,
|
2528
|
+
usage: [{ types: true, FieldDefinition: true }],
|
2552
2529
|
code: /* GraphQL */ `
|
2553
2530
|
type someTypeName {
|
2554
2531
|
name: String
|
@@ -2557,7 +2534,7 @@ const rule$h = {
|
|
2557
2534
|
},
|
2558
2535
|
{
|
2559
2536
|
title: 'Correct',
|
2560
|
-
usage: [{ types: true,
|
2537
|
+
usage: [{ types: true, FieldDefinition: true }],
|
2561
2538
|
code: /* GraphQL */ `
|
2562
2539
|
"""
|
2563
2540
|
Some type description
|
@@ -2574,9 +2551,7 @@ const rule$h = {
|
|
2574
2551
|
configOptions: [
|
2575
2552
|
{
|
2576
2553
|
types: true,
|
2577
|
-
|
2578
|
-
[graphql.Kind.DIRECTIVE_DEFINITION]: true,
|
2579
|
-
},
|
2554
|
+
[graphql.Kind.DIRECTIVE_DEFINITION]: true,
|
2580
2555
|
},
|
2581
2556
|
],
|
2582
2557
|
},
|
@@ -2595,22 +2570,23 @@ const rule$h = {
|
|
2595
2570
|
properties: {
|
2596
2571
|
types: {
|
2597
2572
|
type: 'boolean',
|
2598
|
-
description: `Includes:\n\n${TYPES_KINDS.map(kind => `-
|
2599
|
-
},
|
2600
|
-
overrides: {
|
2601
|
-
type: 'object',
|
2602
|
-
description: 'Configuration for precise `ASTNode`',
|
2603
|
-
additionalProperties: false,
|
2604
|
-
properties: Object.fromEntries(ALLOWED_KINDS$1.map(kind => [kind, { type: 'boolean' }])),
|
2573
|
+
description: `Includes:\n\n${TYPES_KINDS.map(kind => `- \`${kind}\``).join('\n')}`,
|
2605
2574
|
},
|
2575
|
+
...Object.fromEntries([...ALLOWED_KINDS$1].sort().map(kind => [
|
2576
|
+
kind,
|
2577
|
+
{
|
2578
|
+
type: 'boolean',
|
2579
|
+
description: `Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`,
|
2580
|
+
},
|
2581
|
+
])),
|
2606
2582
|
},
|
2607
2583
|
},
|
2608
2584
|
},
|
2609
2585
|
},
|
2610
2586
|
create(context) {
|
2611
|
-
const { types,
|
2587
|
+
const { types, ...restOptions } = context.options[0];
|
2612
2588
|
const kinds = new Set(types ? TYPES_KINDS : []);
|
2613
|
-
for (const [kind, isEnabled] of Object.entries(
|
2589
|
+
for (const [kind, isEnabled] of Object.entries(restOptions)) {
|
2614
2590
|
if (isEnabled) {
|
2615
2591
|
kinds.add(kind);
|
2616
2592
|
}
|