diff options
author | cjihrig <cjihrig@gmail.com> | 2018-06-22 23:05:00 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2018-06-24 12:43:54 -0400 |
commit | 7a3bbbf41be64d04058a158f6986ec5641885f42 (patch) | |
tree | 086e84227091cfc5dfa9eb729f007424cf51feb8 /tools/node_modules/eslint/lib/testers/rule-tester.js | |
parent | d5316bc27df87b62675adec517e5dd3108efd1c2 (diff) | |
download | android-node-v8-7a3bbbf41be64d04058a158f6986ec5641885f42.tar.gz android-node-v8-7a3bbbf41be64d04058a158f6986ec5641885f42.tar.bz2 android-node-v8-7a3bbbf41be64d04058a158f6986ec5641885f42.zip |
tools: update ESLint to 5.0.0
This is a new major release of ESLint.
PR-URL: https://github.com/nodejs/node/pull/20855
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/lib/testers/rule-tester.js')
-rw-r--r-- | tools/node_modules/eslint/lib/testers/rule-tester.js | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/tools/node_modules/eslint/lib/testers/rule-tester.js b/tools/node_modules/eslint/lib/testers/rule-tester.js index de218a875f..318fafe1b6 100644 --- a/tools/node_modules/eslint/lib/testers/rule-tester.js +++ b/tools/node_modules/eslint/lib/testers/rule-tester.js @@ -396,11 +396,10 @@ class RuleTester { * @private */ function assertASTDidntChange(beforeAST, afterAST) { - if (!lodash.isEqual(beforeAST, afterAST)) { - // Not using directly to avoid performance problem in node 6.1.0. See #6111 - // eslint-disable-next-line no-restricted-properties - assert.deepEqual(beforeAST, afterAST, "Rule should not modify AST."); + // Feature detect the Node.js implementation and use that if available. + if ((util.isDeepStrictEqual && !util.isDeepStrictEqual(beforeAST, afterAST)) || !lodash.isEqual(beforeAST, afterAST)) { + assert.fail(null, null, "Rule should not modify AST."); } } @@ -487,36 +486,51 @@ class RuleTester { /* * Error object. - * This may have a message, node type, line, and/or + * This may have a message, messageId, data, node type, line, and/or * column. */ - if (error.message) { + if (hasOwnProperty(error, "message")) { + assert.ok(!hasOwnProperty(error, "messageId"), "Error should not specify both 'message' and a 'messageId'."); + assert.ok(!hasOwnProperty(error, "data"), "Error should not specify both 'data' and 'message'."); assertMessageMatches(message.message, error.message); - } - - if (error.messageId) { - const hOP = Object.hasOwnProperty.call.bind(Object.hasOwnProperty); - - // verify that `error.message` is `undefined` - assert.strictEqual(error.message, void 0, "Error should not specify both a message and a messageId."); - if (!hOP(rule, "meta") || !hOP(rule.meta, "messages")) { - assert.fail("Rule must specify a messages hash in `meta`"); - } - if (!hOP(rule.meta.messages, error.messageId)) { + } else if (hasOwnProperty(error, "messageId")) { + assert.ok( + hasOwnProperty(rule, "meta") && hasOwnProperty(rule.meta, "messages"), + "Error can not use 'messageId' if rule under test doesn't define 'meta.messages'." + ); + if (!hasOwnProperty(rule.meta.messages, error.messageId)) { const friendlyIDList = `[${Object.keys(rule.meta.messages).map(key => `'${key}'`).join(", ")}]`; - assert.fail(`Invalid messageId '${error.messageId}'. Expected one of ${friendlyIDList}.`); + assert(false, `Invalid messageId '${error.messageId}'. Expected one of ${friendlyIDList}.`); } - - let expectedMessage = rule.meta.messages[error.messageId]; - - if (error.data) { - expectedMessage = interpolate(expectedMessage, error.data); + assert.strictEqual( + error.messageId, + message.messageId, + `messageId '${message.messageId}' does not match expected messageId '${error.messageId}'.` + ); + if (hasOwnProperty(error, "data")) { + + /* + * if data was provided, then directly compare the returned message to a synthetic + * interpolated message using the same message ID and data provided in the test. + * See https://github.com/eslint/eslint/issues/9890 for context. + */ + const unformattedOriginalMessage = rule.meta.messages[error.messageId]; + const rehydratedMessage = interpolate(unformattedOriginalMessage, error.data); + + assert.strictEqual( + message.message, + rehydratedMessage, + `Hydrated message "${rehydratedMessage}" does not match "${message.message}"` + ); } - - assertMessageMatches(message.message, expectedMessage); } + assert.ok( + hasOwnProperty(error, "data") ? hasOwnProperty(error, "messageId") : true, + "Error must specify 'messageId' if 'data' is used." + ); + if (error.type) { assert.strictEqual(message.nodeType, error.type, `Error type should be ${error.type}, found ${message.nodeType}`); } @@ -554,8 +568,7 @@ class RuleTester { } else { const fixResult = SourceCodeFixer.applyFixes(item.code, messages); - // eslint-disable-next-line no-restricted-properties - assert.equal(fixResult.output, item.output, "Output is incorrect."); + assert.strictEqual(fixResult.output, item.output, "Output is incorrect."); } } |