forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocumented-errors.js
40 lines (34 loc) · 1.05 KB
/
documented-errors.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
'use strict';
const fs = require('fs');
const path = require('path');
const { isDefiningError } = require('./rules-utils.js');
const doc = fs.readFileSync(path.resolve(__dirname, '../../doc/api/errors.md'),
'utf8');
function isInDoc(code) {
return doc.match(`### ${code}`) != null;
}
function includesAnchor(code) {
return doc.match(`<a id="${code}"></a>`) != null;
}
function errorForNode(node) {
return node.expression.arguments[0].value;
}
module.exports = {
create: function(context) {
return {
ExpressionStatement: function(node) {
if (!isDefiningError(node) || !errorForNode(node)) return;
const code = errorForNode(node);
if (!isInDoc(code)) {
const message = `"${code}" is not documented in doc/api/errors.md`;
context.report({ node, message });
}
if (!includesAnchor(code)) {
const message =
`doc/api/errors.md does not have an anchor for "${code}"`;
context.report({ node, message });
}
}
};
}
};