Skip to content

fix(prefer-wait-for): only report when imported from TL #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2020

Conversation

timdeschryver
Copy link
Member

Closes #151

Comment on lines +130 to +136
context
.getDeclaredVariables(importSpecifier)
.forEach(variable =>
variable.references.forEach(reference =>
reportWait(reference.identifier)
)
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we could make this cleaner? 👀

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps

context
  .getDeclaredVariables(importSpecifier)
  .flatMap(variable => variable.references)
  .forEach(({ identifier })=> reportWait(identifier))

? But IMO it's not too much of a difference - I think this is fine

And I think flatMap does not work in node <= 10

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we can't use flatMap in node 10

Copy link
Member

@Belco90 Belco90 Jun 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could make the code cleaner by extracting the first forEach callback to its own function? It's the only thing I can think of.

code: `
cy.wait();
`,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider testing require scenarios as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we can have an additional test for it, indeed.

Copy link
Member

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR Tim, just a simple request for adding an extra test.

code: `
cy.wait();
`,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we can have an additional test for it, indeed.

@timdeschryver
Copy link
Member Author

This won't be just additional tests, it would also mean that we have to modify the rule.
e.g. the following is currently valid (but invalid with import):

const { wait } = require("@testing-library/foo");

async () => {
  await wait();
}

@Belco90
Copy link
Member

Belco90 commented Jun 10, 2020

Ah of course. Fair enough, I'll approve it then.

@Belco90 Belco90 merged commit b80accf into master Jun 10, 2020
@Belco90 Belco90 deleted the pr/check-import-wait branch June 10, 2020 10:48
@Belco90
Copy link
Member

Belco90 commented Jun 10, 2020

🎉 This PR is included in version 3.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Belco90
Copy link
Member

Belco90 commented Jun 10, 2020

@all-contributors please add @Miguelerja for bug

@allcontributors
Copy link
Contributor

@Belco90

I've put up a pull request to add @Miguelerja! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prefer-wait-for rule autofix is modifying Cypress wait() functions
3 participants