0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/tools/eslint-rules/alphabetize-errors.js
2017-09-28 09:16:20 -04:00

38 lines
910 B
JavaScript

'use strict';
const prefix = 'Out of ASCIIbetical order - ';
const opStr = ' >= ';
function errorForNode(node) {
return node.expression.arguments[0].value;
}
function isDefiningError(node) {
return node.expression &&
node.expression.type === 'CallExpression' &&
node.expression.callee &&
node.expression.callee.name === 'E';
}
module.exports = {
create: function(context) {
let previousNode;
return {
ExpressionStatement: function(node) {
if (!isDefiningError(node)) return;
if (!previousNode) {
previousNode = node;
return;
}
const prev = errorForNode(previousNode);
const curr = errorForNode(node);
previousNode = node;
if (prev >= curr) {
const message = [prefix, prev, opStr, curr].join('');
context.report({ node, message });
}
}
};
}
};