Skip to content

Commit 16935a3

Browse files
committed
more
1 parent df4bb52 commit 16935a3

File tree

7 files changed

+104
-26
lines changed

7 files changed

+104
-26
lines changed

.changeset/happy-bottles-warn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
'@graphql-eslint/eslint-plugin': minor
33
---
44

5-
introduce `forbiddenPattern` and `requiredPattern` options for `naming-convention` rule and
5+
introduce `forbiddenPatterns` and `requiredPatterns` options for `naming-convention` rule and
66
deprecate `forbiddenPrefixes`, `forbiddenSuffixes` and `requiredPrefixes` and `requiredSuffixes`

.changeset/long-chicken-press.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
'@graphql-eslint/eslint-plugin': minor
33
---
44

5-
add new option `ignoredSelectors` for `require-description` rule, to ignore eslint selectors, e.g. types which ends with `Connection` or `Edge`
5+
add new option `ignoredSelectors` for `require-description` rule, to ignore eslint selectors, e.g.
6+
types which ends with `Connection` or `Edge`

packages/plugin/src/rules/naming-convention/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,19 @@ ruleTester.run<RuleOptions>('naming-convention', rule, {
527527
errors: 2,
528528
},
529529
{
530-
name: 'forbiddenPattern',
530+
name: 'forbiddenPatterns',
531531
code: 'query queryFoo { foo } query getBar { bar }',
532-
options: [{ OperationDefinition: { forbiddenPattern: [/^(get|query)/] } }],
532+
options: [{ OperationDefinition: { forbiddenPatterns: [/^(get|query)/] } }],
533533
errors: 2,
534534
},
535535
{
536-
name: 'requiredPattern',
536+
name: 'requiredPatterns',
537537
code: 'type Test { enabled: Boolean! }',
538538
options: [
539539
{
540540
'FieldDefinition[gqlType.gqlType.name.value=Boolean]': {
541541
style: 'camelCase',
542-
requiredPattern: [/^(is|has)/],
542+
requiredPatterns: [/^(is|has)/],
543543
},
544544
},
545545
],

packages/plugin/src/rules/naming-convention/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const schemaOption = {
4848
oneOf: [{ $ref: '#/definitions/asString' }, { $ref: '#/definitions/asObject' }],
4949
} as const;
5050

51-
const descriptionPrefixesSuffixes = (name: 'forbiddenPattern' | 'requiredPattern') =>
51+
const descriptionPrefixesSuffixes = (name: 'forbiddenPatterns' | 'requiredPatterns') =>
5252
`> [!WARNING]
5353
>
5454
> This option is deprecated and will be removed in the next major release. Use [\`${name}\`](#${name.toLowerCase()}-array) instead.`;
@@ -66,14 +66,14 @@ const schema = {
6666
style: { enum: ALLOWED_STYLES },
6767
prefix: { type: 'string' },
6868
suffix: { type: 'string' },
69-
forbiddenPattern: {
69+
forbiddenPatterns: {
7070
...ARRAY_DEFAULT_OPTIONS,
7171
items: {
7272
type: 'object',
7373
},
7474
description: 'Should be of instance of `RegEx`',
7575
},
76-
requiredPattern: {
76+
requiredPatterns: {
7777
...ARRAY_DEFAULT_OPTIONS,
7878
items: {
7979
type: 'object',
@@ -82,19 +82,19 @@ const schema = {
8282
},
8383
forbiddenPrefixes: {
8484
...ARRAY_DEFAULT_OPTIONS,
85-
description: descriptionPrefixesSuffixes('forbiddenPattern'),
85+
description: descriptionPrefixesSuffixes('forbiddenPatterns'),
8686
},
8787
forbiddenSuffixes: {
8888
...ARRAY_DEFAULT_OPTIONS,
89-
description: descriptionPrefixesSuffixes('forbiddenPattern'),
89+
description: descriptionPrefixesSuffixes('forbiddenPatterns'),
9090
},
9191
requiredPrefixes: {
9292
...ARRAY_DEFAULT_OPTIONS,
93-
description: descriptionPrefixesSuffixes('requiredPattern'),
93+
description: descriptionPrefixesSuffixes('requiredPatterns'),
9494
},
9595
requiredSuffixes: {
9696
...ARRAY_DEFAULT_OPTIONS,
97-
description: descriptionPrefixesSuffixes('requiredPattern'),
97+
description: descriptionPrefixesSuffixes('requiredPatterns'),
9898
},
9999
ignorePattern: {
100100
type: 'string',
@@ -152,8 +152,8 @@ type PropertySchema = {
152152
style?: AllowedStyle;
153153
suffix?: string;
154154
prefix?: string;
155-
forbiddenPattern?: RegExp[];
156-
requiredPattern?: RegExp[];
155+
forbiddenPatterns?: RegExp[];
156+
requiredPatterns?: RegExp[];
157157
forbiddenPrefixes?: string[];
158158
forbiddenSuffixes?: string[];
159159
requiredPrefixes?: string[];
@@ -377,8 +377,8 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
377377
ignorePattern,
378378
requiredPrefixes,
379379
requiredSuffixes,
380-
forbiddenPattern,
381-
requiredPattern,
380+
forbiddenPatterns,
381+
requiredPatterns,
382382
} = normalisePropertyOption(selector);
383383
const nodeName = node.value;
384384
const error = getError();
@@ -417,16 +417,16 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
417417
renameToNames: [name + suffix],
418418
};
419419
}
420-
const forbidden = forbiddenPattern?.find(pattern => pattern.test(name));
420+
const forbidden = forbiddenPatterns?.find(pattern => pattern.test(name));
421421
if (forbidden) {
422422
return {
423423
errorMessage: `not contain the forbidden pattern "${forbidden}"`,
424424
renameToNames: [name.replace(forbidden, '')],
425425
};
426426
}
427-
if (requiredPattern && !requiredPattern.some(pattern => pattern.test(name))) {
427+
if (requiredPatterns && !requiredPatterns.some(pattern => pattern.test(name))) {
428428
return {
429-
errorMessage: `contain the required pattern: ${englishJoinWords(requiredPattern.map(re => re.source))}`,
429+
errorMessage: `contain the required pattern: ${englishJoinWords(requiredPatterns.map(re => re.source))}`,
430430
renameToNames: [],
431431
};
432432
}

packages/plugin/src/rules/naming-convention/snapshot.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,40 @@ exports[`naming-convention > invalid > forbiddenPattern 1`] = `
409409
1 | query queryFoo { foo } query Bar { bar }
410410
`;
411411

412+
exports[`naming-convention > invalid > forbiddenPatterns 1`] = `
413+
#### ⌨️ Code
414+
415+
1 | query queryFoo { foo } query getBar { bar }
416+
417+
#### ⚙️ Options
418+
419+
{
420+
"OperationDefinition": {
421+
"forbiddenPatterns": [
422+
"/^(get|query)/"
423+
]
424+
}
425+
}
426+
427+
#### ❌ Error 1/2
428+
429+
> 1 | query queryFoo { foo } query getBar { bar }
430+
| ^^^^^^^^ Query "queryFoo" should not contain the forbidden pattern "/^(get|query)/"
431+
432+
#### 💡 Suggestion: Rename to \`Foo\`
433+
434+
1 | query Foo { foo } query getBar { bar }
435+
436+
#### ❌ Error 2/2
437+
438+
> 1 | query queryFoo { foo } query getBar { bar }
439+
| ^^^^^^ Query "getBar" should not contain the forbidden pattern "/^(get|query)/"
440+
441+
#### 💡 Suggestion: Rename to \`Bar\`
442+
443+
1 | query queryFoo { foo } query Bar { bar }
444+
`;
445+
412446
exports[`naming-convention > invalid > large graphql file 1`] = `
413447
#### ⌨️ Code
414448

@@ -1995,6 +2029,28 @@ exports[`naming-convention > invalid > requiredPattern 1`] = `
19952029
| ^^^^^^^ Field "enabled" should contain the required pattern: ^(is|has)
19962030
`;
19972031

2032+
exports[`naming-convention > invalid > requiredPatterns 1`] = `
2033+
#### ⌨️ Code
2034+
2035+
1 | type Test { enabled: Boolean! }
2036+
2037+
#### ⚙️ Options
2038+
2039+
{
2040+
"FieldDefinition[gqlType.gqlType.name.value=Boolean]": {
2041+
"style": "camelCase",
2042+
"requiredPatterns": [
2043+
"/^(is|has)/"
2044+
]
2045+
}
2046+
}
2047+
2048+
#### ❌ Error
2049+
2050+
> 1 | type Test { enabled: Boolean! }
2051+
| ^^^^^^^ Field "enabled" should contain the required pattern: ^(is|has)
2052+
`;
2053+
19982054
exports[`naming-convention > invalid > schema-recommended config 1`] = `
19992055
#### ⌨️ Code
20002056

website/content/rules/naming-convention.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ This element must be one of the following enum values:
349349

350350
### `suffix` (string)
351351

352-
### `forbiddenPattern` (array)
352+
### `forbiddenPatterns` (array)
353353

354354
Should be of instance of `RegEx`
355355

@@ -362,7 +362,7 @@ Additional restrictions:
362362
- Minimum items: `1`
363363
- Unique items: `true`
364364

365-
### `requiredPattern` (array)
365+
### `requiredPatterns` (array)
366366

367367
Should be of instance of `RegEx`
368368

@@ -380,7 +380,7 @@ Additional restrictions:
380380
> [!WARNING]
381381
>
382382
> This option is deprecated and will be removed in the next major release. Use
383-
> [`forbiddenPattern`](#forbiddenpattern-array) instead.
383+
> [`forbiddenPatterns`](#forbiddenpatterns-array) instead.
384384

385385
The object is an array with all elements of the type `string`.
386386

@@ -394,7 +394,7 @@ Additional restrictions:
394394
> [!WARNING]
395395
>
396396
> This option is deprecated and will be removed in the next major release. Use
397-
> [`forbiddenPattern`](#forbiddenpattern-array) instead.
397+
> [`forbiddenPatterns`](#forbiddenpatterns-array) instead.
398398

399399
The object is an array with all elements of the type `string`.
400400

@@ -408,7 +408,7 @@ Additional restrictions:
408408
> [!WARNING]
409409
>
410410
> This option is deprecated and will be removed in the next major release. Use
411-
> [`requiredPattern`](#requiredpattern-array) instead.
411+
> [`requiredPatterns`](#requiredpatterns-array) instead.
412412

413413
The object is an array with all elements of the type `string`.
414414

@@ -422,7 +422,7 @@ Additional restrictions:
422422
> [!WARNING]
423423
>
424424
> This option is deprecated and will be removed in the next major release. Use
425-
> [`requiredPattern`](#requiredpattern-array) instead.
425+
> [`requiredPatterns`](#requiredpatterns-array) instead.
426426

427427
The object is an array with all elements of the type `string`.
428428

website/content/rules/require-description.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ type User {
7070
}
7171
```
7272

73+
### Correct
74+
75+
```graphql
76+
# eslint @graphql-eslint/require-description: ['error', { ignoredSelectors: ['[type=ObjectTypeDefinition][name.value=PageInfo]', '[type=ObjectTypeDefinition][name.value=/(Connection|Edge)$/]'] }]
77+
78+
type FriendConnection {
79+
edges: [FriendEdge]
80+
pageInfo: PageInfo!
81+
}
82+
type FriendEdge {
83+
cursor: String!
84+
node: Friend!
85+
}
86+
type PageInfo {
87+
hasPreviousPage: Boolean!
88+
hasNextPage: Boolean!
89+
startCursor: String
90+
endCursor: String
91+
}
92+
```
93+
7394
## Config Schema
7495

7596
The schema defines the following properties:

0 commit comments

Comments
 (0)