Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f63acdb

Browse filesBrowse files
refackMylesBorins
authored andcommitted
errors,tools: ASCIIbetical instead of alphabetical
PR-URL: #15578 Fixes: #15576 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 64164c7 commit f63acdb
Copy full SHA for f63acdb

File tree

Expand file treeCollapse file tree

2 files changed

+24
-23
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-23
lines changed
Open diff view settings
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,6 @@ E('ERR_ENCODING_INVALID_ENCODED_DATA',
150150
E('ERR_ENCODING_NOT_SUPPORTED',
151151
(enc) => `The "${enc}" encoding is not supported`);
152152
E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
153-
E('ERR_HTTP_HEADERS_SENT',
154-
'Cannot render headers after they are sent to the client');
155-
E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.');
156-
E('ERR_HTTP_INVALID_STATUS_CODE',
157-
(originalStatusCode) => `Invalid status code: ${originalStatusCode}`);
158-
E('ERR_HTTP_TRAILER_INVALID',
159-
'Trailers are invalid with this transfer encoding');
160153
E('ERR_HTTP2_CONNECT_AUTHORITY',
161154
':authority header is required for CONNECT requests');
162155
E('ERR_HTTP2_CONNECT_PATH',
@@ -171,14 +164,14 @@ E('ERR_HTTP2_FRAME_ERROR',
171164
msg += ` with code ${code}`;
172165
return msg;
173166
});
174-
E('ERR_HTTP2_HEADER_REQUIRED',
175-
(name) => `The ${name} header is required`);
176-
E('ERR_HTTP2_HEADER_SINGLE_VALUE',
177-
(name) => `Header field "${name}" must have only a single value`);
178167
E('ERR_HTTP2_HEADERS_AFTER_RESPOND',
179168
'Cannot specify additional headers after response initiated');
180169
E('ERR_HTTP2_HEADERS_OBJECT', 'Headers must be an object');
181170
E('ERR_HTTP2_HEADERS_SENT', 'Response has already been initiated.');
171+
E('ERR_HTTP2_HEADER_REQUIRED',
172+
(name) => `The ${name} header is required`);
173+
E('ERR_HTTP2_HEADER_SINGLE_VALUE',
174+
(name) => `Header field "${name}" must have only a single value`);
182175
E('ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND',
183176
'Cannot send informational headers after the HTTP message has been sent');
184177
E('ERR_HTTP2_INFO_STATUS_NOT_ALLOWED',
@@ -221,6 +214,13 @@ E('ERR_HTTP2_STREAM_ERROR',
221214
E('ERR_HTTP2_STREAM_SELF_DEPENDENCY', 'A stream cannot depend on itself');
222215
E('ERR_HTTP2_UNSUPPORTED_PROTOCOL',
223216
(protocol) => `protocol "${protocol}" is unsupported.`);
217+
E('ERR_HTTP_HEADERS_SENT',
218+
'Cannot render headers after they are sent to the client');
219+
E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.');
220+
E('ERR_HTTP_INVALID_STATUS_CODE',
221+
(originalStatusCode) => `Invalid status code: ${originalStatusCode}`);
222+
E('ERR_HTTP_TRAILER_INVALID',
223+
'Trailers are invalid with this transfer encoding');
224224
E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
225225
E('ERR_INVALID_ARG_TYPE', invalidArgType);
226226
E('ERR_INVALID_ARRAY_LENGTH',
Collapse file

‎tools/eslint-rules/alphabetize-errors.js‎

Copy file name to clipboardExpand all lines: tools/eslint-rules/alphabetize-errors.js
+13-12Lines changed: 13 additions & 12 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.