Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 01e7b44

Browse filesBrowse files
cjihrigMylesBorins
authored andcommitted
tools: simplify prefer-assert-methods rule
PR-URL: #17572 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
1 parent d59b0a7 commit 01e7b44
Copy full SHA for 01e7b44

File tree

Expand file treeCollapse file tree

1 file changed

+8
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-19
lines changed
Open diff view settings
Collapse file

‎tools/eslint-rules/prefer-assert-methods.js‎

Copy file name to clipboardExpand all lines: tools/eslint-rules/prefer-assert-methods.js
+8-19Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
'use strict';
22

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"]';
136

147
function parseError(method, op) {
158
return `'assert.${method}' should be used instead of '${op}'`;
@@ -24,15 +17,11 @@ const preferedAssertMethod = {
2417

2518
module.exports = function(context) {
2619
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));
3625
}
3726
}
3827
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.