| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,8 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - function isAssert(node) { | ||
| 4 | - return node.expression && | ||
| 5 | - node.expression.type === 'CallExpression' && | ||
| 6 | - node.expression.callee && | ||
| 7 | - node.expression.callee.name === 'assert'; | ||
| 8 | - } | ||
| 9 | - | ||
| 10 | - function getFirstArg(expression) { | ||
| 11 | - return expression.arguments && expression.arguments[0]; | ||
| 12 | - } | ||
| 3 | + const astSelector = 'ExpressionStatement[expression.type="CallExpression"]' + | ||
| 4 | + '[expression.callee.name="assert"]' + | ||
| 5 | + '[expression.arguments.0.type="BinaryExpression"]'; | ||
| 13 | 6 | ||
| 14 | 7 | function parseError(method, op) { | |
| 15 | 8 | return `'assert.${method}' should be used instead of '${op}'`; | |
@@ -24,15 +17,11 @@ const preferedAssertMethod = { | |||
| 24 | 17 | ||
| 25 | 18 | module.exports = function(context) { | |
| 26 | 19 | return { | |
| 27 | - ExpressionStatement(node) { | ||
| 28 | - if (isAssert(node)) { | ||
| 29 | - const arg = getFirstArg(node.expression); | ||
| 30 | - if (arg && arg.type === 'BinaryExpression') { | ||
| 31 | - const assertMethod = preferedAssertMethod[arg.operator]; | ||
| 32 | - if (assertMethod) { | ||
| 33 | - context.report(node, parseError(assertMethod, arg.operator)); | ||
| 34 | - } | ||
| 35 | - } | ||
| 20 | + [astSelector]: function(node) { | ||
| 21 | + const arg = node.expression.arguments[0]; | ||
| 22 | + const assertMethod = preferedAssertMethod[arg.operator]; | ||
| 23 | + if (assertMethod) { | ||
| 24 | + context.report(node, parseError(assertMethod, arg.operator)); | ||
| 36 | 25 | } | |
| 37 | 26 | } | |
| 38 | 27 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments