From 7a7450414460af8bec1bbbac644eff049834faca Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sat, 23 Sep 2017 17:41:04 -0400 Subject: [PATCH] errors,tools: ASCIIbetical instead of alphabetical PR-URL: https://github.com/nodejs/node/pull/15578 Fixes: https://github.com/nodejs/node/issues/15576 Reviewed-By: Luigi Pinca --- lib/internal/errors.js | 23 +++++++++++----------- tools/eslint-rules/alphabetize-errors.js | 25 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 4ebb92ddac358e..2a49313a346983 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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', @@ -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', @@ -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', @@ -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'); diff --git a/tools/eslint-rules/alphabetize-errors.js b/tools/eslint-rules/alphabetize-errors.js index f4651de9a75326..2f604130e995b4 100644 --- a/tools/eslint-rules/alphabetize-errors.js +++ b/tools/eslint-rules/alphabetize-errors.js @@ -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' && @@ -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 }); } } };