Skip to content

Commit

Permalink
errors,tools: ASCIIbetical instead of alphabetical
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#15578
Fixes: nodejs/node#15576
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Refael Ackermann authored and addaleax committed Sep 30, 2017
1 parent fa49f66 commit ee647fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
24 changes: 12 additions & 12 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,6 @@ E('ERR_ENCODING_INVALID_ENCODED_DATA',
E('ERR_ENCODING_NOT_SUPPORTED',
(enc) => `The "${enc}" encoding is not supported`);
E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
E('ERR_HTTP_HEADERS_SENT',
'Cannot %s headers after they are sent to the client');
E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.');
E('ERR_HTTP_INVALID_STATUS_CODE',
(originalStatusCode) => `Invalid status code: ${originalStatusCode}`);
E('ERR_HTTP_TRAILER_INVALID',
'Trailers are invalid with this transfer encoding');
E('ERR_HTTP2_CONNECT_AUTHORITY',
':authority header is required for CONNECT requests');
E('ERR_HTTP2_CONNECT_PATH',
Expand All @@ -158,14 +151,14 @@ E('ERR_HTTP2_FRAME_ERROR',
msg += ` with code ${code}`;
return msg;
});
E('ERR_HTTP2_HEADER_REQUIRED',
(name) => `The ${name} header is required`);
E('ERR_HTTP2_HEADER_SINGLE_VALUE',
(name) => `Header field "${name}" must have only a single value`);
E('ERR_HTTP2_HEADERS_AFTER_RESPOND',
'Cannot specify additional headers after response initiated');
E('ERR_HTTP2_HEADERS_OBJECT', 'Headers must be an object');
E('ERR_HTTP2_HEADERS_SENT', 'Response has already been initiated.');
E('ERR_HTTP2_HEADER_REQUIRED',
(name) => `The ${name} header is required`);
E('ERR_HTTP2_HEADER_SINGLE_VALUE',
(name) => `Header field "${name}" must have only a single value`);
E('ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND',
'Cannot send informational headers after the HTTP message has been sent');
E('ERR_HTTP2_INFO_STATUS_NOT_ALLOWED',
Expand Down Expand Up @@ -204,6 +197,13 @@ E('ERR_HTTP2_STREAM_ERROR',
E('ERR_HTTP2_STREAM_SELF_DEPENDENCY', 'A stream cannot depend on itself');
E('ERR_HTTP2_UNSUPPORTED_PROTOCOL',
(protocol) => `protocol "${protocol}" is unsupported.`);
E('ERR_HTTP_HEADERS_SENT',
'Cannot %s headers after they are sent to the client');
E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.');
E('ERR_HTTP_INVALID_STATUS_CODE',
(originalStatusCode) => `Invalid status code: ${originalStatusCode}`);
E('ERR_HTTP_TRAILER_INVALID',
'Trailers are invalid with this transfer encoding');
E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
E('ERR_INVALID_ARG_TYPE', invalidArgType);
E('ERR_INVALID_ARRAY_LENGTH',
Expand Down Expand Up @@ -258,8 +258,8 @@ E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object');
E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU');
E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range');
E('ERR_OUTOFMEMORY', 'Out of memory');
E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range');
E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s');
E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s');
E('ERR_SERVER_ALREADY_LISTEN',
Expand Down
25 changes: 13 additions & 12 deletions tools/eslint-rules/alphabetize-errors.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
'use strict';

const message = 'Errors in lib/internal/errors.js must be alphabetized';
const prefix = 'Out of ASCIIbetical order - ';
const opStr = ' >= ';

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' &&
Expand All @@ -19,16 +16,20 @@ function isDefiningError(node) {

module.exports = {
create: function(context) {
var previousNode;

let previousNode;
return {
ExpressionStatement: function(node) {
if (isDefiningError(node)) {
if (previousNode && !isAlphabetized(previousNode, node)) {
context.report({ node: node, message: message });
}

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 });
}
}
};
Expand Down

0 comments on commit ee647fc

Please sign in to comment.