Skip to content

Commit

Permalink
improve RuleDocsInfo type, set description and url as required …
Browse files Browse the repository at this point in the history
…fields (#1163)

* improve `RuleDocsInfo` type, set `description` and `url` as required fields

* fixes for eslint-plugin-eslint-plugin 😏
  • Loading branch information
dimaMachina committed Sep 23, 2022
1 parent c33bde9 commit 0d3fe5b
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-zebras-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

improve `RuleDocsInfo` type, set `description` and `url` as required fields
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
'error',
{ pattern: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/{{name}}.md' },
],
'eslint-plugin/prefer-message-ids': 'off',
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"eslint": "8.23.1",
"eslint-config-prettier": "8.5.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-eslint-plugin": "4.1.0",
"eslint-plugin-eslint-plugin": "5.0.6",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.2.3",
"eslint-plugin-promise": "6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/rules/graphql-js-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const handleMissingFragments: GetDocumentNode = ({ ruleId, context, node }) => {
const validationToRule = (
ruleId: string,
ruleName: string,
docs: GraphQLESLintRule['meta']['docs'],
docs: Omit<GraphQLESLintRule['meta']['docs'], 'url'>,
getDocumentNode?: GetDocumentNode,
schema: JSONSchema4 | JSONSchema4[] = []
): Record<typeof ruleId, GraphQLESLintRule<any, true>> => {
Expand Down
1 change: 0 additions & 1 deletion packages/plugin/src/rules/selection-set-depth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const RULE_ID = 'selection-set-depth';
const rule: GraphQLESLintRule<[SelectionSetDepthRuleConfig]> = {
meta: {
type: 'suggestion',
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions -- optional since we can't provide fixes for fragments located in separate files
hasSuggestions: true,
docs: {
category: 'Operations',
Expand Down
41 changes: 22 additions & 19 deletions packages/plugin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,32 @@ export type GraphQLESLintRuleContext<Options = any[]> = Omit<
export type CategoryType = 'Schema' | 'Operations';

export type RuleDocsInfo<T> = {
docs: Omit<Rule.RuleMetaData['docs'], 'category'> & {
category: CategoryType | CategoryType[];
requiresSchema?: true;
requiresSiblings?: true;
examples?: {
title: string;
code: string;
usage?: T;
}[];
configOptions?:
| T
| {
schema?: T;
operations?: T;
};
graphQLJSRuleName?: string;
isDisabledForAllConfig?: true;
};
description: string;
category: CategoryType | CategoryType[];
recommended?: boolean;
url: string;
requiresSchema?: true;
requiresSiblings?: true;
examples?: {
title: string;
code: string;
usage?: T;
}[];
configOptions?:
| T
| {
schema?: T;
operations?: T;
};
graphQLJSRuleName?: string;
isDisabledForAllConfig?: true;
};

export type GraphQLESLintRule<Options = any[], WithTypeInfo extends boolean = false> = {
create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>;
meta: Omit<Rule.RuleMetaData, 'docs'> & RuleDocsInfo<Options>;
meta: Omit<Rule.RuleMetaData, 'docs'> & {
docs: RuleDocsInfo<Options>
};
};

export type ValueOf<T> = T[keyof T];
Expand Down
39 changes: 0 additions & 39 deletions patches/eslint-plugin-eslint-plugin+4.1.0.patch

This file was deleted.

61 changes: 61 additions & 0 deletions patches/eslint-plugin-eslint-plugin+5.0.6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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
index caa646e..29b5177 100644
--- 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
@@ -36,7 +36,7 @@ module.exports = {

const onlyProperty = test.properties.find(
(property) =>
- property.key.type === 'Identifier' &&
+ property.key?.type === 'Identifier' &&
property.key.name === 'only' &&
property.value.type === 'Literal' &&
property.value.value
@@ -82,7 +82,7 @@ module.exports = {
test.type === 'CallExpression' &&
test.callee.type === 'MemberExpression' &&
test.callee.object.type === 'Identifier' &&
- test.callee.object.name === 'RuleTester' &&
+ test.callee.object.name === 'GraphQLRuleTester' &&
test.callee.property.type === 'Identifier' &&
test.callee.property.name === 'only'
) {
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
index 0716d91..2bee9f4 100644
--- 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
@@ -48,7 +48,7 @@ module.exports = {
*/
function getTestInfo(key) {
if (test.type === 'ObjectExpression') {
- return test.properties.find((item) => item.key.name === key);
+ return test.properties.find((item) => item.key?.name === key);
}
return null;
}
diff --git a/node_modules/eslint-plugin-eslint-plugin/lib/utils.js b/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
index 3129903..c7e1d88 100644
--- a/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
+++ b/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
@@ -25,10 +25,10 @@ function isNormalFunctionExpression(node) {
function isRuleTesterConstruction(node) {
return (
node.type === 'NewExpression' &&
- ((node.callee.type === 'Identifier' && node.callee.name === 'RuleTester') ||
+ ((node.callee.type === 'Identifier' && node.callee.name === 'GraphQLRuleTester') ||
(node.callee.type === 'MemberExpression' &&
node.callee.property.type === 'Identifier' &&
- node.callee.property.name === 'RuleTester'))
+ node.callee.property.name === 'GraphQLRuleTester'))
);
}

@@ -534,7 +534,7 @@ module.exports = {
(isRuleTesterConstruction(expression.callee.object) ||
variableIdentifiers.has(expression.callee.object)) &&
expression.callee.property.type === 'Identifier' &&
- expression.callee.property.name === 'run'
+ expression.callee.property.name === 'runGraphQLTests'
) {
runCalls.push(expression);
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3241,10 +3241,10 @@ eslint-plugin-es@^4.1.0:
eslint-utils "^2.0.0"
regexpp "^3.0.0"

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

0 comments on commit 0d3fe5b

Please sign in to comment.