0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-28 06:28:40 +01:00
nodejs/tools/eslint-rules/alphabetize-errors.js
Ruben Bridgewater 7107c9201d
tools: fix custom eslint rule errors
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>
2018-02-22 12:10:22 +01:00

33 lines
769 B
JavaScript

'use strict';
const { isDefiningError } = require('./rules-utils.js');
const prefix = 'Out of ASCIIbetical order - ';
const opStr = ' >= ';
function errorForNode(node) {
return node.expression.arguments[0].value;
}
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 });
}
}
};
}
};