| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3c8b25b commit dcada80
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,18 +10,19 @@ const { isRequireCall, isString } = require('./rules-utils.js'); | |||
| 10 | 10 | // Rule Definition | |
| 11 | 11 | //------------------------------------------------------------------------------ | |
| 12 | 12 | ||
| 13 | + const secondLevelTypes = [ | ||
| 14 | + 'FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression', | ||
| 15 | + 'ClassBody', 'MethodDefinition', | ||
| 16 | + ]; | ||
| 13 | 17 | ||
| 14 | 18 | 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; | ||
| 22 | 23 | } | |
| 23 | - } while (node = node.parent); | ||
| 24 | - return true; | ||
| 24 | + } | ||
| 25 | + return false; | ||
| 25 | 26 | } | |
| 26 | 27 | ||
| 27 | 28 | module.exports = (context) => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments