Skip to content

Commit

Permalink
assert, tools: enforce strict (not)equal in eslint
Browse files Browse the repository at this point in the history
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: #11795
PR-URL: #10698
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
  • Loading branch information
gibfahn authored and MylesBorins committed Apr 14, 2017
1 parent a654502 commit acd9bc3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
26 changes: 15 additions & 11 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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);
Expand Down

0 comments on commit acd9bc3

Please sign in to comment.