-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: enforce deepStrictEqual over deepEqual
Introduce a lint rule that enforces use of `assert.deepStrictEqual()` over `assert.deepEqual()`.
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
}; | ||
}; |