Skip to content

Commit c626ad5

Browse files
authored
fix: handle ImportBindings in no-unnecessary-waiting rule
2 parents 969b222 + ad396fb commit c626ad5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/rules/no-unnecessary-waiting.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ function isIdentifierNumberConstArgument (node, scope) {
6969
return typeof definition.node.init.value === 'number'
7070
}
7171

72+
// import { WAIT } from './constants'
73+
// cy.wait(WAIT)
74+
// we don't know if WAIT is a number or alias '@someRequest', so don't fail
75+
if (definition.type === 'ImportBinding') return false
76+
7277
const param = definition.node.params[definition.index]
7378

7479
// 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)