From d4061a63142004eee4ffc3de5fca7286cd330090 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 9 Sep 2016 20:37:32 -0700 Subject: [PATCH] tools: replace custom ESLint rule with built-in ESLint 3.5.0 introduces a `no-restricted-properties` rule. Replace our custom `no-deepEqual` rule with this rule. PR-URL: https://github.com/nodejs/node/pull/8478 Reviewed-By: James M Snell --- .eslintrc | 6 +++- .../deepequal-prims-and-objs-big-array.js | 2 +- .../deepequal-prims-and-objs-big-loop.js | 2 +- benchmark/assert/deepequal-typedarrays.js | 2 +- lib/assert.js | 2 ++ .../test-assert-typedarray-deepequal.js | 2 +- test/parallel/test-assert.js | 1 - .../test-stream2-readable-from-list.js | 2 +- test/parallel/test-stream2-set-encoding.js | 2 +- test/parallel/test-stream2-transform.js | 2 +- test/parallel/test-stream2-writable.js | 2 +- test/pummel/test-stream2-basic.js | 2 +- tools/eslint-rules/no-deepEqual.js | 32 ------------------- 13 files changed, 16 insertions(+), 43 deletions(-) delete mode 100644 tools/eslint-rules/no-deepEqual.js diff --git a/.eslintrc b/.eslintrc index c51e07b3738c8e..f1525a6309cfb6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -54,6 +54,11 @@ rules: no-new-require: 2 no-path-concat: 2 no-restricted-modules: [2, sys, _linklist] + no-restricted-properties: [2, { + object: assert, + property: deepEqual, + message: Please use assert.deepStrictEqual(). + }] # Stylistic Issues # http://eslint.org/docs/rules/#stylistic-issues @@ -98,7 +103,6 @@ rules: align-multiline-assignment: 2 assert-fail-single-argument: 2 new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError] - no-deepEqual: 2 no-definegetter-definesetter: 2 # Global scoped method and vars diff --git a/benchmark/assert/deepequal-prims-and-objs-big-array.js b/benchmark/assert/deepequal-prims-and-objs-big-array.js index 9bf946a5bf1805..1b4802c8ff4ac2 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-array.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-array.js @@ -1,4 +1,3 @@ -/* eslint no-deepEqual: 0 */ 'use strict'; var common = require('../common.js'); var assert = require('assert'); @@ -35,6 +34,7 @@ function main(conf) { bench.start(); for (x = 0; x < n; x++) { + // eslint-disable-next-line no-restricted-properties assert.deepEqual(primArray, primArrayCompare); } bench.end(n); diff --git a/benchmark/assert/deepequal-prims-and-objs-big-loop.js b/benchmark/assert/deepequal-prims-and-objs-big-loop.js index 8227d532a40e43..dea084bc984126 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-loop.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-loop.js @@ -1,4 +1,3 @@ -/* eslint no-deepEqual: 0 */ 'use strict'; var common = require('../common.js'); var assert = require('assert'); @@ -27,6 +26,7 @@ function main(conf) { bench.start(); for (x = 0; x < n; x++) { + // eslint-disable-next-line no-restricted-properties assert.deepEqual(new Array([prim]), new Array([prim])); } diff --git a/benchmark/assert/deepequal-typedarrays.js b/benchmark/assert/deepequal-typedarrays.js index 654b8b4a79fa5b..1954c57ee59eeb 100644 --- a/benchmark/assert/deepequal-typedarrays.js +++ b/benchmark/assert/deepequal-typedarrays.js @@ -1,4 +1,3 @@ -/* eslint no-deepEqual: 0 */ 'use strict'; var common = require('../common.js'); var assert = require('assert'); @@ -17,6 +16,7 @@ function main(conf) { var actual = new clazz(n * 1e6); var expected = new clazz(n * 1e6); + // eslint-disable-next-line no-restricted-properties assert.deepEqual(actual, expected); bench.end(n); diff --git a/lib/assert.js b/lib/assert.js index 9378631d2763bd..0458bb09816872 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -126,11 +126,13 @@ assert.notEqual = function notEqual(actual, expected, message) { // 7. The equivalence assertion tests a deep equality relation. // assert.deepEqual(actual, expected, message_opt); +/* eslint-disable no-restricted-properties */ assert.deepEqual = function deepEqual(actual, expected, message) { if (!_deepEqual(actual, expected, false)) { fail(actual, expected, message, 'deepEqual', assert.deepEqual); } }; +/* eslint-enable */ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { if (!_deepEqual(actual, expected, true)) { diff --git a/test/parallel/test-assert-typedarray-deepequal.js b/test/parallel/test-assert-typedarray-deepequal.js index 24acd81d6aa6e6..2e6c88848a809f 100644 --- a/test/parallel/test-assert-typedarray-deepequal.js +++ b/test/parallel/test-assert-typedarray-deepequal.js @@ -1,4 +1,3 @@ -/* eslint no-deepEqual: 0 */ 'use strict'; require('../common'); @@ -46,6 +45,7 @@ const notEqualArrayPairs = [ ]; equalArrayPairs.forEach((arrayPair) => { + // eslint-disable-next-line no-restricted-properties assert.deepEqual(arrayPair[0], arrayPair[1]); }); diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 97242363b4fb05..9767ecfe878c19 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -1,4 +1,3 @@ -/* eslint no-deepEqual: 0 */ 'use strict'; require('../common'); var assert = require('assert'); diff --git a/test/parallel/test-stream2-readable-from-list.js b/test/parallel/test-stream2-readable-from-list.js index a823bf9dc10891..2aa0725f734117 100644 --- a/test/parallel/test-stream2-readable-from-list.js +++ b/test/parallel/test-stream2-readable-from-list.js @@ -23,7 +23,7 @@ function run() { var fn = next[1]; console.log('# %s', name); fn({ - same: assert.deepEqual, + same: assert.deepStrictEqual, equal: assert.equal, end: function() { count--; diff --git a/test/parallel/test-stream2-set-encoding.js b/test/parallel/test-stream2-set-encoding.js index dd27c1bb297801..3deb67d48e7156 100644 --- a/test/parallel/test-stream2-set-encoding.js +++ b/test/parallel/test-stream2-set-encoding.js @@ -22,7 +22,7 @@ function run() { var fn = next[1]; console.log('# %s', name); fn({ - same: assert.deepEqual, + same: assert.deepStrictEqual, equal: assert.equal, end: function() { count--; diff --git a/test/parallel/test-stream2-transform.js b/test/parallel/test-stream2-transform.js index e25cdc8e4932ed..bc812ff30d6937 100644 --- a/test/parallel/test-stream2-transform.js +++ b/test/parallel/test-stream2-transform.js @@ -22,7 +22,7 @@ function run() { var fn = next[1]; console.log('# %s', name); fn({ - same: assert.deepEqual, + same: assert.deepStrictEqual, equal: assert.equal, ok: assert, end: function() { diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 6acfcde4efc313..a9d526f8c0a7e4 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -45,7 +45,7 @@ function run() { var fn = next[1]; console.log('# %s', name); fn({ - same: assert.deepEqual, + same: assert.deepStrictEqual, equal: assert.equal, end: function() { count--; diff --git a/test/pummel/test-stream2-basic.js b/test/pummel/test-stream2-basic.js index e03c49f13b9968..6bb2386b0b17dc 100644 --- a/test/pummel/test-stream2-basic.js +++ b/test/pummel/test-stream2-basic.js @@ -85,7 +85,7 @@ function run() { var fn = next[1]; console.log('# %s', name); fn({ - same: assert.deepEqual, + same: assert.deepStrictEqual, ok: assert, equal: assert.equal, end: function() { diff --git a/tools/eslint-rules/no-deepEqual.js b/tools/eslint-rules/no-deepEqual.js deleted file mode 100644 index 46341d7d9238e7..00000000000000 --- a/tools/eslint-rules/no-deepEqual.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @fileoverview Prohibit use of assert.deepEqual() - * @author Rich Trott - * - * This rule is imperfect, but will find the most common forms of - * assert.deepEqual() usage. - */ -'use strict'; - -//------------------------------------------------------------------------------ -// Rule Definition -//------------------------------------------------------------------------------ - -const msg = 'assert.deepEqual() disallowed. Use assert.deepStrictEqual()'; - -function isAssert(node) { - return node.callee.object && node.callee.object.name === 'assert'; -} - -function isDeepEqual(node) { - return node.callee.property && node.callee.property.name === 'deepEqual'; -} - -module.exports = function(context) { - return { - 'CallExpression': function(node) { - if (isAssert(node) && isDeepEqual(node)) { - context.report(node, msg); - } - } - }; -};