Skip to content

Commit 722ad51

Browse files
authored
Added support for Identifier values
1 parent 9086352 commit 722ad51

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/rules/no-unnecessary-waiting.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ module.exports = {
2121
create (context) {
2222
return {
2323
CallExpression (node) {
24-
if (isCallingCyWait(node) && isNumberArgument(node)) {
25-
context.report({ node, messageId: 'unexpected' })
24+
if (isCallingCyWait(node)) {
25+
const scope = context.getScope()
26+
27+
if (isIdentifierNumberConstArgument(node, scope) || isNumberArgument(node)) {
28+
context.report({ node, messageId: 'unexpected' })
29+
}
2630
}
2731
},
2832
}
@@ -42,3 +46,14 @@ function isNumberArgument (node) {
4246
node.arguments[0].type === 'Literal' &&
4347
typeof (node.arguments[0].value) === 'number'
4448
}
49+
50+
function isIdentifierNumberConstArgument (node, scope) {
51+
if (node.arguments[0].type !== 'Identifier') {
52+
return false
53+
}
54+
55+
const resolvedIdentifier = scope.resolve(node.arguments[0]).resolved
56+
const IdentifierValue = resolvedIdentifier.defs[0].node.init.value
57+
58+
return typeof IdentifierValue === 'number'
59+
}

0 commit comments

Comments
 (0)