Skip to content

Commit

Permalink
errors,tools: ASCIIbetical instead of alphabetical
Browse files Browse the repository at this point in the history
PR-URL: #15578
Fixes: #15576
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
refack authored and MylesBorins committed Oct 3, 2017
1 parent b22014e commit 7a74504
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
23 changes: 11 additions & 12 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,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 render 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 @@ -146,14 +139,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 @@ -192,6 +185,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 render 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 @@ -255,7 +255,6 @@ E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
E('ERR_VALID_PERFORMANCE_ENTRY_TYPE',
'At least one valid performance entry type is required');
// Add new errors from here...

function invalidArgType(name, expected, actual) {
internalAssert(name, 'name is required');
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 7a74504

Please sign in to comment.