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 dcada80

Browse filesBrowse files
Trotttargos
authored andcommitted
tools: remove conditional assignment in custom ESLint rule
These changes no-duplicate-require.js so that it doesn't use an assignment in a conditional, which can be easy to misread as a comparison rather than an assignment. It also means we change a do/while (which we don't use much in our code) to the much more common while construct. PR-URL: #41325 Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 3c8b25b commit dcada80
Copy full SHA for dcada80

File tree

Expand file treeCollapse file tree

1 file changed

+10
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-9
lines changed
Open diff view settings
Collapse file

‎tools/eslint-rules/no-duplicate-requires.js‎

Copy file name to clipboardExpand all lines: tools/eslint-rules/no-duplicate-requires.js
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ const { isRequireCall, isString } = require('./rules-utils.js');
1010
// Rule Definition
1111
//------------------------------------------------------------------------------
1212

13+
const secondLevelTypes = [
14+
'FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression',
15+
'ClassBody', 'MethodDefinition',
16+
];
1317

1418
function isTopLevel(node) {
15-
do {
16-
if (node.type === 'FunctionDeclaration' ||
17-
node.type === 'FunctionExpression' ||
18-
node.type === 'ArrowFunctionExpression' ||
19-
node.type === 'ClassBody' ||
20-
node.type === 'MethodDefinition') {
21-
return false;
19+
while (!secondLevelTypes.includes(node.type)) {
20+
node = node.parent;
21+
if (!node) {
22+
return true;
2223
}
23-
} while (node = node.parent);
24-
return true;
24+
}
25+
return false;
2526
}
2627

2728
module.exports = (context) => {

0 commit comments

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