Skip to content

Commit 5f46944

Browse files
committed
errors,tools: ASCIIbetical instead of alphabetical
PR-URL: #15578 Fixes: #15576 Reviewed-By: Luigi Pinca <[email protected]>
1 parent 2b196fb commit 5f46944

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

lib/internal/errors.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,6 @@ E('ERR_ENCODING_INVALID_ENCODED_DATA',
137137
E('ERR_ENCODING_NOT_SUPPORTED',
138138
(enc) => `The "${enc}" encoding is not supported`);
139139
E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
140-
E('ERR_HTTP_HEADERS_SENT',
141-
'Cannot %s headers after they are sent to the client');
142-
E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.');
143-
E('ERR_HTTP_INVALID_STATUS_CODE',
144-
(originalStatusCode) => `Invalid status code: ${originalStatusCode}`);
145-
E('ERR_HTTP_TRAILER_INVALID',
146-
'Trailers are invalid with this transfer encoding');
147140
E('ERR_HTTP2_CONNECT_AUTHORITY',
148141
':authority header is required for CONNECT requests');
149142
E('ERR_HTTP2_CONNECT_PATH',
@@ -158,14 +151,14 @@ E('ERR_HTTP2_FRAME_ERROR',
158151
msg += ` with code ${code}`;
159152
return msg;
160153
});
161-
E('ERR_HTTP2_HEADER_REQUIRED',
162-
(name) => `The ${name} header is required`);
163-
E('ERR_HTTP2_HEADER_SINGLE_VALUE',
164-
(name) => `Header field "${name}" must have only a single value`);
165154
E('ERR_HTTP2_HEADERS_AFTER_RESPOND',
166155
'Cannot specify additional headers after response initiated');
167156
E('ERR_HTTP2_HEADERS_OBJECT', 'Headers must be an object');
168157
E('ERR_HTTP2_HEADERS_SENT', 'Response has already been initiated.');
158+
E('ERR_HTTP2_HEADER_REQUIRED',
159+
(name) => `The ${name} header is required`);
160+
E('ERR_HTTP2_HEADER_SINGLE_VALUE',
161+
(name) => `Header field "${name}" must have only a single value`);
169162
E('ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND',
170163
'Cannot send informational headers after the HTTP message has been sent');
171164
E('ERR_HTTP2_INFO_STATUS_NOT_ALLOWED',
@@ -204,6 +197,13 @@ E('ERR_HTTP2_STREAM_ERROR',
204197
E('ERR_HTTP2_STREAM_SELF_DEPENDENCY', 'A stream cannot depend on itself');
205198
E('ERR_HTTP2_UNSUPPORTED_PROTOCOL',
206199
(protocol) => `protocol "${protocol}" is unsupported.`);
200+
E('ERR_HTTP_HEADERS_SENT',
201+
'Cannot %s headers after they are sent to the client');
202+
E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.');
203+
E('ERR_HTTP_INVALID_STATUS_CODE',
204+
(originalStatusCode) => `Invalid status code: ${originalStatusCode}`);
205+
E('ERR_HTTP_TRAILER_INVALID',
206+
'Trailers are invalid with this transfer encoding');
207207
E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
208208
E('ERR_INVALID_ARG_TYPE', invalidArgType);
209209
E('ERR_INVALID_ARRAY_LENGTH',
@@ -258,8 +258,8 @@ E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object');
258258
E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
259259
E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU');
260260
E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
261-
E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range');
262261
E('ERR_OUTOFMEMORY', 'Out of memory');
262+
E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range');
263263
E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s');
264264
E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s');
265265
E('ERR_SERVER_ALREADY_LISTEN',

tools/eslint-rules/alphabetize-errors.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
'use strict';
22

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

56
function errorForNode(node) {
67
return node.expression.arguments[0].value;
78
}
89

9-
function isAlphabetized(previousNode, node) {
10-
return errorForNode(previousNode).localeCompare(errorForNode(node)) < 0;
11-
}
12-
1310
function isDefiningError(node) {
1411
return node.expression &&
1512
node.expression.type === 'CallExpression' &&
@@ -19,16 +16,20 @@ function isDefiningError(node) {
1916

2017
module.exports = {
2118
create: function(context) {
22-
var previousNode;
23-
19+
let previousNode;
2420
return {
2521
ExpressionStatement: function(node) {
26-
if (isDefiningError(node)) {
27-
if (previousNode && !isAlphabetized(previousNode, node)) {
28-
context.report({ node: node, message: message });
29-
}
30-
22+
if (!isDefiningError(node)) return;
23+
if (!previousNode) {
3124
previousNode = node;
25+
return;
26+
}
27+
const prev = errorForNode(previousNode);
28+
const curr = errorForNode(node);
29+
previousNode = node;
30+
if (prev >= curr) {
31+
const message = [prefix, prev, opStr, curr].join('');
32+
context.report({ node, message });
3233
}
3334
}
3435
};

0 commit comments

Comments
 (0)