mirror of https://github.com/lukechilds/node.git
Browse Source
PR-URL: https://github.com/nodejs/node/pull/8622 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: Jackson Tian <shvyo1987@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>v7.x
Dany Shaanan
8 years ago
committed by
James M Snell
48 changed files with 151 additions and 90 deletions
@ -0,0 +1,39 @@ |
|||
'use strict'; |
|||
|
|||
function isAssert(node) { |
|||
return node.expression && |
|||
node.expression.type === 'CallExpression' && |
|||
node.expression.callee && |
|||
node.expression.callee.name === 'assert'; |
|||
} |
|||
|
|||
function getFirstArg(expression) { |
|||
return expression.arguments && expression.arguments[0]; |
|||
} |
|||
|
|||
function parseError(method, op) { |
|||
return `'assert.${method}' should be used instead of '${op}'`; |
|||
} |
|||
|
|||
const preferedAssertMethod = { |
|||
'===': 'strictEqual', |
|||
'!==': 'notStrictEqual', |
|||
'==': 'equal', |
|||
'!=': 'notEqual' |
|||
}; |
|||
|
|||
module.exports = function(context) { |
|||
return { |
|||
ExpressionStatement(node) { |
|||
if (isAssert(node)) { |
|||
const arg = getFirstArg(node.expression); |
|||
if (arg && arg.type === 'BinaryExpression') { |
|||
const assertMethod = preferedAssertMethod[arg.operator]; |
|||
if (assertMethod) { |
|||
context.report(node, parseError(assertMethod, arg.operator)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}; |
|||
}; |
Loading…
Reference in new issue