Skip to content

Commit 0d3fe5b

Browse files
authored
improve RuleDocsInfo type, set description and url as required fields (#1163)
* improve `RuleDocsInfo` type, set `description` and `url` as required fields * fixes for eslint-plugin-eslint-plugin 😏
1 parent c33bde9 commit 0d3fe5b

File tree

9 files changed

+95
-65
lines changed

9 files changed

+95
-65
lines changed

.changeset/odd-zebras-search.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+
improve `RuleDocsInfo` type, set `description` and `url` as required fields

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = {
3939
'error',
4040
{ pattern: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/{{name}}.md' },
4141
],
42+
'eslint-plugin/prefer-message-ids': 'off',
4243
},
4344
},
4445
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"eslint": "8.23.1",
4242
"eslint-config-prettier": "8.5.0",
4343
"eslint-config-standard": "17.0.0",
44-
"eslint-plugin-eslint-plugin": "4.1.0",
44+
"eslint-plugin-eslint-plugin": "5.0.6",
4545
"eslint-plugin-import": "2.26.0",
4646
"eslint-plugin-n": "15.2.3",
4747
"eslint-plugin-promise": "6.0.0",

packages/plugin/src/rules/graphql-js-validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const handleMissingFragments: GetDocumentNode = ({ ruleId, context, node }) => {
135135
const validationToRule = (
136136
ruleId: string,
137137
ruleName: string,
138-
docs: GraphQLESLintRule['meta']['docs'],
138+
docs: Omit<GraphQLESLintRule['meta']['docs'], 'url'>,
139139
getDocumentNode?: GetDocumentNode,
140140
schema: JSONSchema4 | JSONSchema4[] = []
141141
): Record<typeof ruleId, GraphQLESLintRule<any, true>> => {

packages/plugin/src/rules/selection-set-depth.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const RULE_ID = 'selection-set-depth';
1313
const rule: GraphQLESLintRule<[SelectionSetDepthRuleConfig]> = {
1414
meta: {
1515
type: 'suggestion',
16-
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions -- optional since we can't provide fixes for fragments located in separate files
1716
hasSuggestions: true,
1817
docs: {
1918
category: 'Operations',

packages/plugin/src/types.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,32 @@ export type GraphQLESLintRuleContext<Options = any[]> = Omit<
5353
export type CategoryType = 'Schema' | 'Operations';
5454

5555
export type RuleDocsInfo<T> = {
56-
docs: Omit<Rule.RuleMetaData['docs'], 'category'> & {
57-
category: CategoryType | CategoryType[];
58-
requiresSchema?: true;
59-
requiresSiblings?: true;
60-
examples?: {
61-
title: string;
62-
code: string;
63-
usage?: T;
64-
}[];
65-
configOptions?:
66-
| T
67-
| {
68-
schema?: T;
69-
operations?: T;
70-
};
71-
graphQLJSRuleName?: string;
72-
isDisabledForAllConfig?: true;
73-
};
56+
description: string;
57+
category: CategoryType | CategoryType[];
58+
recommended?: boolean;
59+
url: string;
60+
requiresSchema?: true;
61+
requiresSiblings?: true;
62+
examples?: {
63+
title: string;
64+
code: string;
65+
usage?: T;
66+
}[];
67+
configOptions?:
68+
| T
69+
| {
70+
schema?: T;
71+
operations?: T;
72+
};
73+
graphQLJSRuleName?: string;
74+
isDisabledForAllConfig?: true;
7475
};
7576

7677
export type GraphQLESLintRule<Options = any[], WithTypeInfo extends boolean = false> = {
7778
create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>;
78-
meta: Omit<Rule.RuleMetaData, 'docs'> & RuleDocsInfo<Options>;
79+
meta: Omit<Rule.RuleMetaData, 'docs'> & {
80+
docs: RuleDocsInfo<Options>
81+
};
7982
};
8083

8184
export type ValueOf<T> = T[keyof T];

patches/eslint-plugin-eslint-plugin+4.1.0.patch

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
diff --git a/node_modules/eslint-plugin-eslint-plugin/lib/rules/no-only-tests.js b/node_modules/eslint-plugin-eslint-plugin/lib/rules/no-only-tests.js
2+
index caa646e..29b5177 100644
3+
--- a/node_modules/eslint-plugin-eslint-plugin/lib/rules/no-only-tests.js
4+
+++ b/node_modules/eslint-plugin-eslint-plugin/lib/rules/no-only-tests.js
5+
@@ -36,7 +36,7 @@ module.exports = {
6+
7+
const onlyProperty = test.properties.find(
8+
(property) =>
9+
- property.key.type === 'Identifier' &&
10+
+ property.key?.type === 'Identifier' &&
11+
property.key.name === 'only' &&
12+
property.value.type === 'Literal' &&
13+
property.value.value
14+
@@ -82,7 +82,7 @@ module.exports = {
15+
test.type === 'CallExpression' &&
16+
test.callee.type === 'MemberExpression' &&
17+
test.callee.object.type === 'Identifier' &&
18+
- test.callee.object.name === 'RuleTester' &&
19+
+ test.callee.object.name === 'GraphQLRuleTester' &&
20+
test.callee.property.type === 'Identifier' &&
21+
test.callee.property.name === 'only'
22+
) {
23+
diff --git a/node_modules/eslint-plugin-eslint-plugin/lib/rules/prefer-output-null.js b/node_modules/eslint-plugin-eslint-plugin/lib/rules/prefer-output-null.js
24+
index 0716d91..2bee9f4 100644
25+
--- a/node_modules/eslint-plugin-eslint-plugin/lib/rules/prefer-output-null.js
26+
+++ b/node_modules/eslint-plugin-eslint-plugin/lib/rules/prefer-output-null.js
27+
@@ -48,7 +48,7 @@ module.exports = {
28+
*/
29+
function getTestInfo(key) {
30+
if (test.type === 'ObjectExpression') {
31+
- return test.properties.find((item) => item.key.name === key);
32+
+ return test.properties.find((item) => item.key?.name === key);
33+
}
34+
return null;
35+
}
36+
diff --git a/node_modules/eslint-plugin-eslint-plugin/lib/utils.js b/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
37+
index 3129903..c7e1d88 100644
38+
--- a/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
39+
+++ b/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
40+
@@ -25,10 +25,10 @@ function isNormalFunctionExpression(node) {
41+
function isRuleTesterConstruction(node) {
42+
return (
43+
node.type === 'NewExpression' &&
44+
- ((node.callee.type === 'Identifier' && node.callee.name === 'RuleTester') ||
45+
+ ((node.callee.type === 'Identifier' && node.callee.name === 'GraphQLRuleTester') ||
46+
(node.callee.type === 'MemberExpression' &&
47+
node.callee.property.type === 'Identifier' &&
48+
- node.callee.property.name === 'RuleTester'))
49+
+ node.callee.property.name === 'GraphQLRuleTester'))
50+
);
51+
}
52+
53+
@@ -534,7 +534,7 @@ module.exports = {
54+
(isRuleTesterConstruction(expression.callee.object) ||
55+
variableIdentifiers.has(expression.callee.object)) &&
56+
expression.callee.property.type === 'Identifier' &&
57+
- expression.callee.property.name === 'run'
58+
+ expression.callee.property.name === 'runGraphQLTests'
59+
) {
60+
runCalls.push(expression);
61+
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,10 +3241,10 @@ eslint-plugin-es@^4.1.0:
32413241
eslint-utils "^2.0.0"
32423242
regexpp "^3.0.0"
32433243

3244-
eslint-plugin-eslint-plugin@4.1.0:
3245-
version "4.1.0"
3246-
resolved "https://registry.yarnpkg.com/eslint-plugin-eslint-plugin/-/eslint-plugin-eslint-plugin-4.1.0.tgz#40ae944d79e845dc9d4a85328eea3c5bf4ae0f7d"
3247-
integrity sha512-QJVw+WYXJuG2469gx5G929bz7crfxySDlK1i569FkuT6dpeHDeP7MmDrKaswCx17snG25LRFD6wmVX+AO5x7Qg==
3244+
eslint-plugin-eslint-plugin@5.0.6:
3245+
version "5.0.6"
3246+
resolved "https://registry.yarnpkg.com/eslint-plugin-eslint-plugin/-/eslint-plugin-eslint-plugin-5.0.6.tgz#76a32444b90525f5e58b1b7bdf0295110f6573a8"
3247+
integrity sha512-q1/sXPSMEAINj9jmYQDp0f7zu0PeU6Wy5Cn/l7OsjSGkq8NLCckFXZxhVIlGJcmAI+OeFSGfRSZ6Iku3eRv8QQ==
32483248
dependencies:
32493249
eslint-utils "^3.0.0"
32503250
estraverse "^5.2.0"

0 commit comments

Comments
 (0)