Skip to content

Commit df4bb52

Browse files
committed
more
1 parent f9d97f9 commit df4bb52

File tree

6 files changed

+60
-19
lines changed

6 files changed

+60
-19
lines changed

.changeset/long-chicken-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': minor
3+
---
4+
5+
add new option `ignoredSelectors` for `require-description` rule, to ignore eslint selectors, e.g. types which ends with `Connection` or `Edge`

packages/plugin/src/rules/no-unused-fields/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FromSchema } from 'json-schema-to-ts';
44
import { ModuleCache } from '../../cache.js';
55
import { SiblingOperations } from '../../siblings.js';
66
import { GraphQLESLintRule, GraphQLESTreeNode } from '../../types.js';
7-
import { eslintSelectorsTip, requireGraphQLOperations, requireGraphQLSchema } from "../../utils.js";
7+
import { eslintSelectorsTip, requireGraphQLOperations, requireGraphQLSchema } from '../../utils.js';
88

99
const RULE_ID = 'no-unused-fields';
1010

@@ -89,7 +89,7 @@ const schema = {
8989
'```json',
9090
JSON.stringify(RELAY_DEFAULT_IGNORED_FIELD_SELECTORS, null, 2),
9191
'```',
92-
eslintSelectorsTip
92+
eslintSelectorsTip,
9393
].join('\n'),
9494
items: {
9595
type: 'string',

packages/plugin/src/rules/require-description/index.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,16 @@ ruleTester.run<RuleOptions>('require-description', rule, {
229229
errors: [{ messageId: RULE_ID }],
230230
},
231231
{
232-
only: true,
233232
name: 'ignoredSelectors',
234-
options: [{ types: true,
235-
ignoredSelectors: [
236-
'[type=ObjectTypeDefinition][name.value=PageInfo]',
237-
'[type=ObjectTypeDefinition][name.value=/(Connection|Edge)$/]',
238-
]
239-
}],
233+
options: [
234+
{
235+
types: true,
236+
ignoredSelectors: [
237+
'[type=ObjectTypeDefinition][name.value=PageInfo]',
238+
'[type=ObjectTypeDefinition][name.value=/(Connection|Edge)$/]',
239+
],
240+
},
241+
],
240242
code: /* GraphQL */ `
241243
type Query {
242244
user: User
@@ -266,7 +268,7 @@ ruleTester.run<RuleOptions>('require-description', rule, {
266268
}
267269
`,
268270
errors: 3,
269-
}
271+
},
270272
],
271273
});
272274

packages/plugin/src/rules/require-description/index.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { getRootTypeNames } from '@graphql-tools/utils';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { GraphQLESLintRule, ValueOf } from '../../types.js';
55
import {
6-
ARRAY_DEFAULT_OPTIONS, eslintSelectorsTip,
6+
ARRAY_DEFAULT_OPTIONS,
7+
eslintSelectorsTip,
78
getLocation,
89
getNodeName,
910
requireGraphQLSchema,
10-
TYPES_KINDS
11-
} from "../../utils.js";
11+
TYPES_KINDS,
12+
} from '../../utils.js';
1213

1314
export const RULE_ID = 'require-description';
1415

@@ -46,15 +47,21 @@ const schema = {
4647
},
4748
ignoredSelectors: {
4849
...ARRAY_DEFAULT_OPTIONS,
49-
description: ['Ignore specific selectors', eslintSelectorsTip].join('\n')
50+
description: ['Ignore specific selectors', eslintSelectorsTip].join('\n'),
5051
},
5152
...Object.fromEntries(
5253
[...ALLOWED_KINDS].sort().map(kind => {
5354
let description = `> [!NOTE]
5455
>
5556
> Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
5657
if (kind === Kind.OPERATION_DEFINITION) {
57-
description += ['','','> [!WARNING]', '>', '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'].join('\n')
58+
description += [
59+
'',
60+
'',
61+
'> [!WARNING]',
62+
'>',
63+
'> You must use only comment syntax `#` and not description syntax `"""` or `"`.',
64+
].join('\n');
5865
}
5966
return [kind, { type: 'boolean', description }];
6067
}),
@@ -129,6 +136,33 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
129136
}
130137
`,
131138
},
139+
{
140+
title: 'Correct',
141+
usage: [
142+
{
143+
ignoredSelectors: [
144+
'[type=ObjectTypeDefinition][name.value=PageInfo]',
145+
'[type=ObjectTypeDefinition][name.value=/(Connection|Edge)$/]',
146+
],
147+
},
148+
],
149+
code: /* GraphQL */ `
150+
type FriendConnection {
151+
edges: [FriendEdge]
152+
pageInfo: PageInfo!
153+
}
154+
type FriendEdge {
155+
cursor: String!
156+
node: Friend!
157+
}
158+
type PageInfo {
159+
hasPreviousPage: Boolean!
160+
hasNextPage: Boolean!
161+
startCursor: String
162+
endCursor: String
163+
}
164+
`,
165+
},
132166
],
133167
configOptions: [
134168
{
@@ -168,7 +202,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
168202
}
169203
let selector = `:matches(${[...kinds]})`;
170204
for (const str of ignoredSelectors) {
171-
selector += `:not(${str})`
205+
selector += `:not(${str})`;
172206
}
173207
return {
174208
[selector](node: SelectorNode) {

packages/plugin/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,4 @@ export function getNodeName(node: GraphQLESTreeNode<ASTNode>): string {
204204
export const eslintSelectorsTip = `> [!TIP]
205205
>
206206
> These fields are defined by ESLint [\`selectors\`](https://eslint.org/docs/developer-guide/selectors).
207-
> Paste or drop code into the editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your selector.`
207+
> Paste or drop code into the editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your selector.`;

packages/rule-tester/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function applyFix(code: string, { range, text }: Rule.Fix): string {
2626
}
2727

2828
// @ts-expect-error -- Extend RegExp with a custom toJSON method
29-
RegExp.prototype.toJSON = function() {
30-
return `/${this.source}/${this.flags}`
29+
RegExp.prototype.toJSON = function () {
30+
return `/${this.source}/${this.flags}`;
3131
};
3232

3333
export class RuleTester<ParserOptions> extends ESLintRuleTester {

0 commit comments

Comments
 (0)