From 6509d747ee9c9276d432d80d6e1c081363136432 Mon Sep 17 00:00:00 2001 From: Gibson Fahnestock Date: Sun, 8 Jan 2017 23:23:34 +0000 Subject: [PATCH] assert, tools: enforce strict (not)equal in eslint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend no-restricted-properties to catch use of assert.equal() and assert.notEqual() and require assert.strictEqual() or assert.notStrictEqual() instead. Also update the eslint-ignore in lib/assert.js to avoid assert.equal/notEqual linter errors in their definitions. PR-URL: https://github.com/nodejs/node/pull/10698 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Michaƫl Zasso Reviewed-By: Teddy Katz --- .eslintrc | 28 ++++++++++++++++------------ lib/assert.js | 3 +-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.eslintrc b/.eslintrc index cf1f36c86bcbdc..4f691caefd3a78 100644 --- a/.eslintrc +++ b/.eslintrc @@ -62,17 +62,21 @@ 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(). - }, { - property: __defineGetter__, - message: __defineGetter__ is deprecated. - }, { - property: __defineSetter__, - message: __defineSetter__ is deprecated. - }] + no-restricted-properties: + - 2 + - object: assert + property: deepEqual + message: Use assert.deepStrictEqual(). + - object: assert + property: equal + message: Use assert.strictEqual() rather than assert.equal(). + - object: assert + property: notEqual + message: Use assert.notStrictEqual() rather than assert.notEqual(). + - property: __defineGetter__ + message: __defineGetter__ is deprecated. + - property: __defineSetter__, + message: __defineSetter__ is deprecated. # Stylistic Issues # http://eslint.org/docs/rules/#stylistic-issues @@ -86,7 +90,7 @@ rules: func-name-matching: 2 indent: [2, 2, {ArrayExpression: first, CallExpression: {arguments: first}, - MemberExpression: 1, + MemberExpression: 1, ObjectExpression: first, SwitchCase: 1}] key-spacing: [2, {mode: minimum}] diff --git a/lib/assert.js b/lib/assert.js index 892df6d9a0f4e2..7f69ba0c60e476 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -109,7 +109,7 @@ assert.ok = ok; // The equality assertion tests shallow, coercive equality with // ==. // assert.equal(actual, expected, message_opt); - +/* eslint-disable no-restricted-properties */ assert.equal = function equal(actual, expected, message) { if (actual != expected) fail(actual, expected, message, '==', assert.equal); }; @@ -127,7 +127,6 @@ assert.notEqual = function notEqual(actual, expected, message) { // 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);