mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
const fs = require('fs');
|
||
|
const path = require('path');
|
||
|
const { isDefiningDeprecation } = require('./rules-utils.js');
|
||
|
|
||
|
const patternToMatch = /^DEP\d+$/;
|
||
|
|
||
|
const mdFile = 'doc/api/deprecations.md';
|
||
|
const doc = fs.readFileSync(path.resolve(__dirname, '../..', mdFile), 'utf8');
|
||
|
|
||
|
function isInDoc(code) {
|
||
|
return doc.includes(`### ${code}:`);
|
||
|
}
|
||
|
|
||
|
function getDeprecationCode(node) {
|
||
|
return node.expression.arguments[2].value;
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
create: function(context) {
|
||
|
return {
|
||
|
ExpressionStatement: function(node) {
|
||
|
if (!isDefiningDeprecation(node) || !getDeprecationCode(node)) return;
|
||
|
const code = getDeprecationCode(node);
|
||
|
if (!patternToMatch.test(code)) {
|
||
|
const message = `"${code}" does not match the expected pattern`;
|
||
|
context.report({ node, message });
|
||
|
}
|
||
|
if (!isInDoc(code)) {
|
||
|
const message = `"${code}" is not documented in ${mdFile}`;
|
||
|
context.report({ node, message });
|
||
|
}
|
||
|
},
|
||
|
};
|
||
|
},
|
||
|
};
|