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>
v6.x
Rich Trott 8 years ago
committed by Jeremiah Senkpiel
parent
commit
f47ce9d9f8
  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-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

2
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);

2
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]));
}

2
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);

2
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)) {

2
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]);
});

1
test/parallel/test-assert.js

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

2
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--;

2
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--;

2
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() {

2
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--;

2
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() {

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