Skip to content

Commit 5e3c6ee

Browse files
author
Dimitri POSTOLOV
authored
enable require-meta-docs-url rule (#618)
1 parent 75165c6 commit 5e3c6ee

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ module.exports = {
3030
'unicorn/prefer-array-some': 'error',
3131
'unicorn/prefer-includes': 'error',
3232
'eslint-plugin/test-case-shorthand-strings': 'error',
33+
'eslint-plugin/require-meta-docs-url': [
34+
'error',
35+
{ pattern: 'https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/{{name}}.md' },
36+
],
3337
},
3438
overrides: [
3539
{

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

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
diff --git a/node_modules/eslint-plugin-eslint-plugin/lib/rules/require-meta-docs-url.js b/node_modules/eslint-plugin-eslint-plugin/lib/rules/require-meta-docs-url.js
2+
index ed7d67a..af8ea5c 100644
3+
--- a/node_modules/eslint-plugin-eslint-plugin/lib/rules/require-meta-docs-url.js
4+
+++ b/node_modules/eslint-plugin-eslint-plugin/lib/rules/require-meta-docs-url.js
5+
@@ -48,7 +48,7 @@ module.exports = {
6+
const options = context.options[0] || {};
7+
const sourceCode = context.getSourceCode();
8+
const filename = context.getFilename();
9+
- const ruleName = filename === '<input>' ? undefined : path.basename(filename, '.js');
10+
+ const ruleName = filename === '<input>' ? undefined : path.basename(filename, '.ts');
11+
const expectedUrl = !options.pattern || !ruleName
12+
? undefined
13+
: options.pattern.replace(/{{\s*name\s*}}/g, ruleName);
114
diff --git a/node_modules/eslint-plugin-eslint-plugin/lib/utils.js b/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
2-
index e00aada..555ec69 100644
15+
index e00aada..9eeb3b9 100644
316
--- a/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
417
+++ b/node_modules/eslint-plugin-eslint-plugin/lib/utils.js
518
@@ -76,10 +76,10 @@ function isNormalFunctionExpressionReference (node, scopeManager) {
@@ -15,7 +28,58 @@ index e00aada..555ec69 100644
1528
);
1629
}
1730

18-
@@ -239,7 +239,7 @@ module.exports = {
31+
@@ -98,7 +98,15 @@ module.exports = {
32+
let exportsVarOverridden = false;
33+
let exportsIsFunction = false;
34+
35+
- const exportNodes = ast.body
36+
+ const collectProps = (parsedProps, prop) => {
37+
+ const keyValue = module.exports.getKeyName(prop);
38+
+ if (INTERESTING_KEYS.has(keyValue)) {
39+
+ parsedProps[keyValue] = prop.value;
40+
+ }
41+
+ return parsedProps;
42+
+ };
43+
+
44+
+ let exportNodes = ast.body
45+
.filter(statement => statement.type === 'ExpressionStatement')
46+
.map(statement => statement.expression)
47+
.filter(expression => expression.type === 'AssignmentExpression')
48+
@@ -119,13 +127,7 @@ module.exports = {
49+
// Check `module.exports = { create: function () {}, meta: {} }`
50+
51+
exportsIsFunction = false;
52+
- return node.right.properties.reduce((parsedProps, prop) => {
53+
- const keyValue = module.exports.getKeyName(prop);
54+
- if (INTERESTING_KEYS.has(keyValue)) {
55+
- parsedProps[keyValue] = prop.value;
56+
- }
57+
- return parsedProps;
58+
- }, {});
59+
+ return node.right.properties.reduce(collectProps, {});
60+
}
61+
return {};
62+
} else if (
63+
@@ -150,6 +152,18 @@ module.exports = {
64+
return currentExports;
65+
}, {});
66+
67+
+ exportNodes = Object.keys(exportNodes).length > 0
68+
+ ? exportNodes
69+
+ : ast.body.filter(statement => statement.type === "VariableDeclaration")
70+
+ .flatMap(statement => statement.declarations)
71+
+ .filter(statement => statement.init?.properties)
72+
+ .reduce((nodes, statement) => {
73+
+ return {
74+
+ ...nodes,
75+
+ ...statement.init.properties.reduce(collectProps, {})
76+
+ };
77+
+ }, {});
78+
+
79+
const createExists = Object.prototype.hasOwnProperty.call(exportNodes, 'create');
80+
if (!createExists) {
81+
return null;
82+
@@ -239,7 +253,7 @@ module.exports = {
1983
variableIdentifiers.has(statement.expression.callee.object)
2084
) &&
2185
statement.expression.callee.property.type === 'Identifier' &&

0 commit comments

Comments
 (0)