2016-09-17 12:32:33 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-12-09 09:54:33 -05:00
|
|
|
const astSelector = 'ExpressionStatement[expression.type="CallExpression"]' +
|
|
|
|
'[expression.callee.name="assert"]' +
|
|
|
|
'[expression.arguments.0.type="BinaryExpression"]';
|
2016-09-17 12:32:33 +02:00
|
|
|
|
|
|
|
function parseError(method, op) {
|
|
|
|
return `'assert.${method}' should be used instead of '${op}'`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const preferedAssertMethod = {
|
|
|
|
'===': 'strictEqual',
|
|
|
|
'!==': 'notStrictEqual',
|
|
|
|
'==': 'equal',
|
|
|
|
'!=': 'notEqual'
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = function(context) {
|
|
|
|
return {
|
2017-12-09 09:54:33 -05:00
|
|
|
[astSelector]: function(node) {
|
|
|
|
const arg = node.expression.arguments[0];
|
|
|
|
const assertMethod = preferedAssertMethod[arg.operator];
|
|
|
|
if (assertMethod) {
|
|
|
|
context.report(node, parseError(assertMethod, arg.operator));
|
2016-09-17 12:32:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|