Skip to content

Commit 58ae363

Browse files
committed
support import bindings in no-unnecessary-waiting rule
1 parent 874c51f commit 58ae363

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/rules/no-unnecessary-waiting.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function isIdentifierNumberConstArgument (node, scope) {
6060
const resolvedIdentifier = scope.references.find((ref) => ref.identifier === identifier).resolved
6161
const definition = resolvedIdentifier.defs[0]
6262
const isVariable = definition.type === 'Variable'
63+
const isImportBinding = definition.type === 'ImportBinding'
6364

6465
// const amount = 1000 or const amount = '@alias'
6566
// cy.wait(amount)
@@ -69,6 +70,12 @@ function isIdentifierNumberConstArgument (node, scope) {
6970
return typeof definition.node.init.value === 'number'
7071
}
7172

73+
// import { WAIT_TIME } from './constants'
74+
// cy.wait(WAIT_TIME)
75+
if (isImportBinding) {
76+
return false
77+
}
78+
7279
const param = definition.node.params[definition.index]
7380

7481
// function wait (amount) { cy.wait(amount) }

tests/lib/rules/no-unnecessary-waiting.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const RuleTester = require('eslint').RuleTester
66
const ruleTester = new RuleTester()
77

88
const errors = [{ messageId: 'unexpected' }]
9-
const parserOptions = { ecmaVersion: 6 }
9+
const parserOptions = { ecmaVersion: 6, sourceType: 'module' }
1010

1111
ruleTester.run('no-unnecessary-waiting', rule, {
1212
valid: [
@@ -27,6 +27,11 @@ ruleTester.run('no-unnecessary-waiting', rule, {
2727
{ code: 'function customWait (ms) { cy.wait(ms) }', parserOptions, errors },
2828
{ code: 'const customWait = (ms) => { cy.wait(ms) }', parserOptions, errors },
2929

30+
{ code: 'import BAR_BAZ from "bar-baz"; cy.wait(BAR_BAZ)', parserOptions },
31+
{ code: 'import { FOO_BAR } from "foo-bar"; cy.wait(FOO_BAR)', parserOptions },
32+
{ code: 'import * as wildcard from "wildcard"; cy.wait(wildcard.value)', parserOptions },
33+
{ code: 'import { NAME as OTHER_NAME } from "rename"; cy.wait(OTHER_NAME)', parserOptions },
34+
3035
// disable the eslint rule
3136
{
3237
code: `

0 commit comments

Comments
 (0)