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.

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>
  • Loading branch information
gibfahn authored and italoacasas committed Jan 30, 2017
1 parent 51f4c8b commit c217b43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
28 changes: 16 additions & 12 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 All @@ -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}]
Expand Down
3 changes: 1 addition & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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);
Expand Down

0 comments on commit c217b43

Please sign in to comment.