forked from eslint-community/eslint-plugin-eslint-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequire-meta-docs-recommended.js
46 lines (40 loc) · 1.16 KB
/
require-meta-docs-recommended.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const utils = require('../utils');
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description:
'require rules to implement a `meta.docs.recommended` property',
category: 'Rules',
recommended: false,
url: 'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/require-meta-docs-recommended.md',
},
fixable: null,
schema: [],
messages: {
missing: '`meta.docs.recommended` is required.',
},
},
create(context) {
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
const ruleInfo = utils.getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
}
const { scopeManager } = sourceCode;
const {
docsNode,
metaNode,
metaPropertyNode: descriptionNode,
} = utils.getMetaProperty('recommended', ruleInfo, scopeManager);
if (!descriptionNode) {
context.report({
node: docsNode || metaNode || ruleInfo.create,
messageId: 'missing',
});
}
return {};
},
};