0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/tools/eslint-rules/alphabetize-errors.js
Antoine du Hamel 3ce4cef4e6
tools: enforce use of trailing commas in tools/
PR-URL: https://github.com/nodejs/node/pull/45889
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2022-12-18 16:39:39 +00:00

33 lines
771 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 });
}
},
};
},
};