Permalink
Browse files

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: #8478
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
Trott authored and Fishrock123 committed Sep 10, 2016
1 parent 36235ac commit f47ce9d9f8dc9b443afcd72951bb0bc96737b7f7
View
@@ -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
@@ -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);
@@ -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]));
}
@@ -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);
View
@@ -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)) {
@@ -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,4 +1,3 @@
-/* eslint no-deepEqual: 0 */
'use strict';
require('../common');
var assert = require('assert');
@@ -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--;
@@ -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--;
@@ -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() {
@@ -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--;
@@ -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() {
@@ -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);
- }
- }
- };
-};

0 comments on commit f47ce9d

Please sign in to comment.