Skip to content

Commit

Permalink
support import bindings in no-unnecessary-waiting rule
Browse files Browse the repository at this point in the history
  • Loading branch information
walaszczykm committed Sep 7, 2022
1 parent 874c51f commit 58ae363
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/rules/no-unnecessary-waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function isIdentifierNumberConstArgument (node, scope) {
const resolvedIdentifier = scope.references.find((ref) => ref.identifier === identifier).resolved
const definition = resolvedIdentifier.defs[0]
const isVariable = definition.type === 'Variable'
const isImportBinding = definition.type === 'ImportBinding'

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

// import { WAIT_TIME } from './constants'
// cy.wait(WAIT_TIME)
if (isImportBinding) {
return false
}

const param = definition.node.params[definition.index]

// function wait (amount) { cy.wait(amount) }
Expand Down
7 changes: 6 additions & 1 deletion tests/lib/rules/no-unnecessary-waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const RuleTester = require('eslint').RuleTester
const ruleTester = new RuleTester()

const errors = [{ messageId: 'unexpected' }]
const parserOptions = { ecmaVersion: 6 }
const parserOptions = { ecmaVersion: 6, sourceType: 'module' }

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

{ code: 'import BAR_BAZ from "bar-baz"; cy.wait(BAR_BAZ)', parserOptions },
{ code: 'import { FOO_BAR } from "foo-bar"; cy.wait(FOO_BAR)', parserOptions },
{ code: 'import * as wildcard from "wildcard"; cy.wait(wildcard.value)', parserOptions },
{ code: 'import { NAME as OTHER_NAME } from "rename"; cy.wait(OTHER_NAME)', parserOptions },

// disable the eslint rule
{
code: `
Expand Down

0 comments on commit 58ae363

Please sign in to comment.