Browse Source

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 <jasnell@gmail.com>
v7.x
Rich Trott 8 years ago
parent
commit
d4061a6314
  1. 6
      .eslintrc
  2. 2
      benchmark/assert/deepequal-prims-and-objs-big-array.js
  3. 2
      benchmark/assert/deepequal-prims-and-objs-big-loop.js
  4. 2
      benchmark/assert/deepequal-typedarrays.js
  5. 2
      lib/assert.js
  6. 2
      test/parallel/test-assert-typedarray-deepequal.js
  7. 1
      test/parallel/test-assert.js
  8. 2
      test/parallel/test-stream2-readable-from-list.js
  9. 2
      test/parallel/test-stream2-set-encoding.js
  10. 2
      test/parallel/test-stream2-transform.js
  11. 2
      test/parallel/test-stream2-writable.js
  12. 2
      test/pummel/test-stream2-basic.js
  13. 32
      tools/eslint-rules/no-deepEqual.js

6
.eslintrc

@ -54,6 +54,11 @@ rules:
no-new-require: 2 no-new-require: 2
no-path-concat: 2 no-path-concat: 2
no-restricted-modules: [2, sys, _linklist] no-restricted-modules: [2, sys, _linklist]
no-restricted-properties: [2, {
object: assert,
property: deepEqual,
message: Please use assert.deepStrictEqual().
}]
# Stylistic Issues # Stylistic Issues
# http://eslint.org/docs/rules/#stylistic-issues # http://eslint.org/docs/rules/#stylistic-issues
@ -98,7 +103,6 @@ rules:
align-multiline-assignment: 2 align-multiline-assignment: 2
assert-fail-single-argument: 2 assert-fail-single-argument: 2
new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError] new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError]
no-deepEqual: 2
no-definegetter-definesetter: 2 no-definegetter-definesetter: 2
# Global scoped method and vars # Global scoped method and vars

2
benchmark/assert/deepequal-prims-and-objs-big-array.js

@ -1,4 +1,3 @@
/* eslint no-deepEqual: 0 */
'use strict'; 'use strict';
var common = require('../common.js'); var common = require('../common.js');
var assert = require('assert'); var assert = require('assert');
@ -35,6 +34,7 @@ function main(conf) {
bench.start(); bench.start();
for (x = 0; x < n; x++) { for (x = 0; x < n; x++) {
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(primArray, primArrayCompare); assert.deepEqual(primArray, primArrayCompare);
} }
bench.end(n); bench.end(n);

2
benchmark/assert/deepequal-prims-and-objs-big-loop.js

@ -1,4 +1,3 @@
/* eslint no-deepEqual: 0 */
'use strict'; 'use strict';
var common = require('../common.js'); var common = require('../common.js');
var assert = require('assert'); var assert = require('assert');
@ -27,6 +26,7 @@ function main(conf) {
bench.start(); bench.start();
for (x = 0; x < n; x++) { for (x = 0; x < n; x++) {
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(new Array([prim]), new Array([prim])); assert.deepEqual(new Array([prim]), new Array([prim]));
} }

2
benchmark/assert/deepequal-typedarrays.js

@ -1,4 +1,3 @@
/* eslint no-deepEqual: 0 */
'use strict'; 'use strict';
var common = require('../common.js'); var common = require('../common.js');
var assert = require('assert'); var assert = require('assert');
@ -17,6 +16,7 @@ function main(conf) {
var actual = new clazz(n * 1e6); var actual = new clazz(n * 1e6);
var expected = new clazz(n * 1e6); var expected = new clazz(n * 1e6);
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(actual, expected); assert.deepEqual(actual, expected);
bench.end(n); bench.end(n);

2
lib/assert.js

@ -126,11 +126,13 @@ assert.notEqual = function notEqual(actual, expected, message) {
// 7. The equivalence assertion tests a deep equality relation. // 7. The equivalence assertion tests a deep equality relation.
// assert.deepEqual(actual, expected, message_opt); // assert.deepEqual(actual, expected, message_opt);
/* eslint-disable no-restricted-properties */
assert.deepEqual = function deepEqual(actual, expected, message) { assert.deepEqual = function deepEqual(actual, expected, message) {
if (!_deepEqual(actual, expected, false)) { if (!_deepEqual(actual, expected, false)) {
fail(actual, expected, message, 'deepEqual', assert.deepEqual); fail(actual, expected, message, 'deepEqual', assert.deepEqual);
} }
}; };
/* eslint-enable */
assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
if (!_deepEqual(actual, expected, true)) { if (!_deepEqual(actual, expected, true)) {

2
test/parallel/test-assert-typedarray-deepequal.js

@ -1,4 +1,3 @@
/* eslint no-deepEqual: 0 */
'use strict'; 'use strict';
require('../common'); require('../common');
@ -46,6 +45,7 @@ const notEqualArrayPairs = [
]; ];
equalArrayPairs.forEach((arrayPair) => { equalArrayPairs.forEach((arrayPair) => {
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(arrayPair[0], arrayPair[1]); assert.deepEqual(arrayPair[0], arrayPair[1]);
}); });

1
test/parallel/test-assert.js

@ -1,4 +1,3 @@
/* eslint no-deepEqual: 0 */
'use strict'; 'use strict';
require('../common'); require('../common');
var assert = require('assert'); var assert = require('assert');

2
test/parallel/test-stream2-readable-from-list.js

@ -23,7 +23,7 @@ function run() {
var fn = next[1]; var fn = next[1];
console.log('# %s', name); console.log('# %s', name);
fn({ fn({
same: assert.deepEqual, same: assert.deepStrictEqual,
equal: assert.equal, equal: assert.equal,
end: function() { end: function() {
count--; count--;

2
test/parallel/test-stream2-set-encoding.js

@ -22,7 +22,7 @@ function run() {
var fn = next[1]; var fn = next[1];
console.log('# %s', name); console.log('# %s', name);
fn({ fn({
same: assert.deepEqual, same: assert.deepStrictEqual,
equal: assert.equal, equal: assert.equal,
end: function() { end: function() {
count--; count--;

2
test/parallel/test-stream2-transform.js

@ -22,7 +22,7 @@ function run() {
var fn = next[1]; var fn = next[1];
console.log('# %s', name); console.log('# %s', name);
fn({ fn({
same: assert.deepEqual, same: assert.deepStrictEqual,
equal: assert.equal, equal: assert.equal,
ok: assert, ok: assert,
end: function() { end: function() {

2
test/parallel/test-stream2-writable.js

@ -45,7 +45,7 @@ function run() {
var fn = next[1]; var fn = next[1];
console.log('# %s', name); console.log('# %s', name);
fn({ fn({
same: assert.deepEqual, same: assert.deepStrictEqual,
equal: assert.equal, equal: assert.equal,
end: function() { end: function() {
count--; count--;

2
test/pummel/test-stream2-basic.js

@ -85,7 +85,7 @@ function run() {
var fn = next[1]; var fn = next[1];
console.log('# %s', name); console.log('# %s', name);
fn({ fn({
same: assert.deepEqual, same: assert.deepStrictEqual,
ok: assert, ok: assert,
equal: assert.equal, equal: assert.equal,
end: function() { end: function() {

32
tools/eslint-rules/no-deepEqual.js

@ -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);
}
}
};
};
Loading…
Cancel
Save