mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
7107c9201d
This fixes a few rules by making sure the input is actually ready to be checked. Otherwise those can throw TypeErrors or result in faulty error messages. PR-URL: https://github.com/nodejs/node/pull/18853 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
'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 });
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|