Skip to content

Commit

Permalink
tools: enforce deepStrictEqual over deepEqual
Browse files Browse the repository at this point in the history
Introduce a lint rule that enforces use of `assert.deepStrictEqual()`
over `assert.deepEqual()`.
  • Loading branch information
Trott committed Apr 20, 2016
1 parent 77ad3a7 commit f0d728c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ rules:
prefer-const: 2

# Custom rules in tools/eslint-rules
align-multiline-assignment: 2
assert-fail-single-argument: 2
new-with-error: [2, "Error", "RangeError", "TypeError", "SyntaxError", "ReferenceError"]
align-multiline-assignment: 2
no-deepEqual: 2

# Global scoped method and vars
globals:
Expand Down
32 changes: 32 additions & 0 deletions tools/eslint-rules/no-deepEqual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @fileoverview Prohibit use of assert.deepEqual()
* @author Rich Trott
*
* This rule is imperfect, but will find the most common forms of
* assert.deepEqual() usage.
*/
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

const msg = 'assert.deepEqual() disallowed. Use assert.deepStrictEqual()';

function isAssert(node) {
return node.callee.object && node.callee.object.name === 'assert';
}

function isDeepEqual(node) {
return node.callee.property && node.callee.property.name === 'deepEqual';
}

module.exports = function(context) {
return {
'CallExpression': function(node) {
if (isAssert(node) && isDeepEqual(node)) {
context.report(node, msg);
}
}
};
};

0 comments on commit f0d728c

Please sign in to comment.