errors,tools: alphabetize-errors lint rule
To make sure errors in lib/internal/errors.js (are defined via `E`) will stay in alphabetical order going forward. PR-URL: https://github.com/nodejs/node/pull/15083 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
324aa6488f
commit
b12d77977e
@ -1,3 +1,5 @@
|
|||||||
|
/* eslint-enable alphabetize-errors */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// The whole point behind this internal module is to allow Node.js to no
|
// The whole point behind this internal module is to allow Node.js to no
|
||||||
|
36
tools/eslint-rules/alphabetize-errors.js
Normal file
36
tools/eslint-rules/alphabetize-errors.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const message = 'Errors in lib/internal/errors.js must be alphabetized';
|
||||||
|
|
||||||
|
function errorForNode(node) {
|
||||||
|
return node.expression.arguments[0].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAlphabetized(previousNode, node) {
|
||||||
|
return errorForNode(previousNode).localeCompare(errorForNode(node)) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDefiningError(node) {
|
||||||
|
return node.expression &&
|
||||||
|
node.expression.type === 'CallExpression' &&
|
||||||
|
node.expression.callee &&
|
||||||
|
node.expression.callee.name === 'E';
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
create: function(context) {
|
||||||
|
var previousNode;
|
||||||
|
|
||||||
|
return {
|
||||||
|
ExpressionStatement: function(node) {
|
||||||
|
if (isDefiningError(node)) {
|
||||||
|
if (previousNode && !isAlphabetized(previousNode, node)) {
|
||||||
|
context.report({ node: node, message: message });
|
||||||
|
}
|
||||||
|
|
||||||
|
previousNode = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user