mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 09:52:21 +00:00

Introduce a lint rule that enforces use of `assert.deepStrictEqual()` over `assert.deepEqual()`. PR-URL: https://github.com/nodejs/node/pull/6213 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
33 lines
852 B
JavaScript
33 lines
852 B
JavaScript
/**
|
|
* @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);
|
|
}
|
|
}
|
|
};
|
|
};
|