Skip to content

Commit 2c91688

Browse files
Trottjoelostrowski
authored andcommitted
tools: enforce deepStrictEqual over deepEqual
Introduce a lint rule that enforces use of `assert.deepStrictEqual()` over `assert.deepEqual()`. PR-URL: nodejs#6213 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 0d4f51d commit 2c91688

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ rules:
8585
prefer-const: 2
8686

8787
# Custom rules in tools/eslint-rules
88+
align-multiline-assignment: 2
8889
assert-fail-single-argument: 2
8990
new-with-error: [2, "Error", "RangeError", "TypeError", "SyntaxError", "ReferenceError"]
90-
align-multiline-assignment: 2
91+
no-deepEqual: 2
9192

9293
# Global scoped method and vars
9394
globals:

tools/eslint-rules/no-deepEqual.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @fileoverview Prohibit use of assert.deepEqual()
3+
* @author Rich Trott
4+
*
5+
* This rule is imperfect, but will find the most common forms of
6+
* assert.deepEqual() usage.
7+
*/
8+
'use strict';
9+
10+
//------------------------------------------------------------------------------
11+
// Rule Definition
12+
//------------------------------------------------------------------------------
13+
14+
const msg = 'assert.deepEqual() disallowed. Use assert.deepStrictEqual()';
15+
16+
function isAssert(node) {
17+
return node.callee.object && node.callee.object.name === 'assert';
18+
}
19+
20+
function isDeepEqual(node) {
21+
return node.callee.property && node.callee.property.name === 'deepEqual';
22+
}
23+
24+
module.exports = function(context) {
25+
return {
26+
'CallExpression': function(node) {
27+
if (isAssert(node) && isDeepEqual(node)) {
28+
context.report(node, msg);
29+
}
30+
}
31+
};
32+
};

0 commit comments

Comments
 (0)