Skip to content

Commit f9d97f9

Browse files
committed
more
1 parent 803626a commit f9d97f9

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { ASTKindToNode, Kind, TokenKind } from 'graphql';
22
import { getRootTypeNames } from '@graphql-tools/utils';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { GraphQLESLintRule, ValueOf } from '../../types.js';
5-
import { getLocation, getNodeName, requireGraphQLSchema, TYPES_KINDS } from '../../utils.js';
5+
import {
6+
ARRAY_DEFAULT_OPTIONS, eslintSelectorsTip,
7+
getLocation,
8+
getNodeName,
9+
requireGraphQLSchema,
10+
TYPES_KINDS
11+
} from "../../utils.js";
612

713
export const RULE_ID = 'require-description';
814

@@ -30,18 +36,25 @@ const schema = {
3036
properties: {
3137
types: {
3238
type: 'boolean',
39+
enum: [true],
3340
description: `Includes:\n${TYPES_KINDS.map(kind => `- \`${kind}\``).join('\n')}`,
3441
},
3542
rootField: {
3643
type: 'boolean',
44+
enum: [true],
3745
description: 'Definitions within `Query`, `Mutation`, and `Subscription` root types.',
3846
},
47+
ignoredSelectors: {
48+
...ARRAY_DEFAULT_OPTIONS,
49+
description: ['Ignore specific selectors', eslintSelectorsTip].join('\n')
50+
},
3951
...Object.fromEntries(
4052
[...ALLOWED_KINDS].sort().map(kind => {
41-
let description = `Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
53+
let description = `> [!NOTE]
54+
>
55+
> Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
4256
if (kind === Kind.OPERATION_DEFINITION) {
43-
description +=
44-
'\n> You must use only comment syntax `#` and not description syntax `"""` or `"`.';
57+
description += ['','','> [!WARNING]', '>', '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'].join('\n')
4558
}
4659
return [kind, { type: 'boolean', description }];
4760
}),
@@ -55,8 +68,9 @@ export type RuleOptions = [
5568
{
5669
[key in AllowedKind]?: boolean;
5770
} & {
58-
types?: boolean;
59-
rootField?: boolean;
71+
types?: true;
72+
rootField?: true;
73+
ignoredSelectors?: string[];
6074
},
6175
];
6276

@@ -132,7 +146,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
132146
schema,
133147
},
134148
create(context) {
135-
const { types, rootField, ...restOptions } = context.options[0] || {};
149+
let { types, rootField, ignoredSelectors = [], ...restOptions } = context.options[0] || {};
136150

137151
const kinds = new Set<string>(types ? TYPES_KINDS : []);
138152
for (const [kind, isEnabled] of Object.entries(restOptions)) {
@@ -152,13 +166,10 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
152166
].join(',')})$/] > FieldDefinition`,
153167
);
154168
}
155-
156-
if (!kinds.size) {
157-
throw new Error('At least one kind must be enabled');
169+
let selector = `:matches(${[...kinds]})`;
170+
for (const str of ignoredSelectors) {
171+
selector += `:not(${str})`
158172
}
159-
160-
const selector = [...kinds].join(',');
161-
162173
return {
163174
[selector](node: SelectorNode) {
164175
let description = '';

website/content/rules/no-unused-fields.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ in the schema:
145145
]
146146
```
147147

148+
> [!TIP]
149+
>
148150
> These fields are defined by ESLint
149151
> [`selectors`](https://eslint.org/docs/developer-guide/selectors). Paste or drop code into the
150152
> editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your

website/content/rules/require-description.mdx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type User {
7474

7575
The schema defines the following properties:
7676

77-
### `types` (boolean)
77+
### `types` (boolean, enum)
7878

7979
Includes:
8080

@@ -85,10 +85,36 @@ Includes:
8585
- `InputObjectTypeDefinition`
8686
- `UnionTypeDefinition`
8787

88-
### `rootField` (boolean)
88+
This element must be one of the following enum values:
89+
90+
- `true`
91+
92+
### `rootField` (boolean, enum)
8993

9094
Definitions within `Query`, `Mutation`, and `Subscription` root types.
9195

96+
This element must be one of the following enum values:
97+
98+
- `true`
99+
100+
### `ignoredSelectors` (array)
101+
102+
Ignore specific selectors
103+
104+
> [!TIP]
105+
>
106+
> These fields are defined by ESLint
107+
> [`selectors`](https://eslint.org/docs/developer-guide/selectors). Paste or drop code into the
108+
> editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your
109+
> selector.
110+
111+
The object is an array with all elements of the type `string`.
112+
113+
Additional restrictions:
114+
115+
- Minimum items: `1`
116+
- Unique items: `true`
117+
92118
### `DirectiveDefinition` (boolean)
93119

94120
> [!NOTE]
@@ -147,9 +173,13 @@ Definitions within `Query`, `Mutation`, and `Subscription` root types.
147173

148174
### `OperationDefinition` (boolean)
149175

150-
Read more about this kind on
151-
[spec.graphql.org](https://spec.graphql.org/October2021/#OperationDefinition).
176+
> [!NOTE]
177+
>
178+
> Read more about this kind on
179+
> [spec.graphql.org](https://spec.graphql.org/October2021/#OperationDefinition).
152180

181+
> [!WARNING]
182+
>
153183
> You must use only comment syntax `#` and not description syntax `"""` or `"`.
154184

155185
### `ScalarTypeDefinition` (boolean)

0 commit comments

Comments
 (0)