Skip to content

Commit 6509d74

Browse files
committed
assert, tools: enforce strict (not)equal in eslint
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: #10698 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
1 parent 3d2aef3 commit 6509d74

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

.eslintrc

+16-12
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,21 @@ rules:
6262
no-new-require: 2
6363
no-path-concat: 2
6464
no-restricted-modules: [2, sys, _linklist]
65-
no-restricted-properties: [2, {
66-
object: assert,
67-
property: deepEqual,
68-
message: Please use assert.deepStrictEqual().
69-
}, {
70-
property: __defineGetter__,
71-
message: __defineGetter__ is deprecated.
72-
}, {
73-
property: __defineSetter__,
74-
message: __defineSetter__ is deprecated.
75-
}]
65+
no-restricted-properties:
66+
- 2
67+
- object: assert
68+
property: deepEqual
69+
message: Use assert.deepStrictEqual().
70+
- object: assert
71+
property: equal
72+
message: Use assert.strictEqual() rather than assert.equal().
73+
- object: assert
74+
property: notEqual
75+
message: Use assert.notStrictEqual() rather than assert.notEqual().
76+
- property: __defineGetter__
77+
message: __defineGetter__ is deprecated.
78+
- property: __defineSetter__,
79+
message: __defineSetter__ is deprecated.
7680

7781
# Stylistic Issues
7882
# http://eslint.org/docs/rules/#stylistic-issues
@@ -86,7 +90,7 @@ rules:
8690
func-name-matching: 2
8791
indent: [2, 2, {ArrayExpression: first,
8892
CallExpression: {arguments: first},
89-
MemberExpression: 1,
93+
MemberExpression: 1,
9094
ObjectExpression: first,
9195
SwitchCase: 1}]
9296
key-spacing: [2, {mode: minimum}]

lib/assert.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ assert.ok = ok;
109109
// The equality assertion tests shallow, coercive equality with
110110
// ==.
111111
// assert.equal(actual, expected, message_opt);
112-
112+
/* eslint-disable no-restricted-properties */
113113
assert.equal = function equal(actual, expected, message) {
114114
if (actual != expected) fail(actual, expected, message, '==', assert.equal);
115115
};
@@ -127,7 +127,6 @@ assert.notEqual = function notEqual(actual, expected, message) {
127127
// The equivalence assertion tests a deep equality relation.
128128
// assert.deepEqual(actual, expected, message_opt);
129129

130-
/* eslint-disable no-restricted-properties */
131130
assert.deepEqual = function deepEqual(actual, expected, message) {
132131
if (!_deepEqual(actual, expected, false)) {
133132
fail(actual, expected, message, 'deepEqual', assert.deepEqual);

0 commit comments

Comments
 (0)