mirror of https://github.com/lukechilds/node.git
Browse Source
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>canary-base
Jon Moss
7 years ago
committed by
Refael Ackermann
2 changed files with 38 additions and 0 deletions
@ -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…
Reference in new issue