From acd9bc315b214ea226c43413acaa351495e594b6 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. Backport-PR-URL: https://github.com/nodejs/node/pull/11795 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.yaml | 26 +++++++++++++++----------- lib/assert.js | 3 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 713e2f1c93d08d..7db9a842792212 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -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 diff --git a/lib/assert.js b/lib/assert.js index f18cc45fc3fe2f..219842f953a12c 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -105,7 +105,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); }; @@ -123,7 +123,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);