Skip to content
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

ESLint rule for non-nested first await #104

Merged
merged 8 commits into from
Mar 27, 2023

Conversation

michaelfig
Copy link
Member

@michaelfig michaelfig commented Mar 23, 2023

This relaxes the restrictions imposed by @jessie.js/no-nested-await so that only the first await needs to be non-nested.

Also add some unit tests to better track the rule in the future.

@michaelfig michaelfig requested a review from mhofman March 23, 2023 17:01
@michaelfig michaelfig force-pushed the mfig-lint-nonnested-first-await branch 2 times, most recently from f9cce72 to 8fa98d6 Compare March 23, 2023 23:55
@michaelfig michaelfig changed the title Nonnested first await lint rule ESLint rule for non-nested first await Mar 24, 2023
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

I didn't fully step through the detection logic. I'm confident in its correctness from the test cases but I don't know if there's a more performant implementation.

Will approve after test cases are well organized.

packages/eslint-plugin/lib/rules/no-nested-await.js Outdated Show resolved Hide resolved
packages/eslint-plugin/test/corpus.js Outdated Show resolved Hide resolved
packages/eslint-plugin/lib/rules/no-nested-await.js Outdated Show resolved Hide resolved
@michaelfig michaelfig force-pushed the mfig-lint-nonnested-first-await branch 2 times, most recently from ccb1895 to 27b817d Compare March 24, 2023 19:48
@michaelfig michaelfig requested a review from turadg March 26, 2023 21:37
packages/eslint-plugin/lib/rules/no-nested-await.js Outdated Show resolved Hide resolved
@@ -90,17 +94,15 @@ module.exports = {
if (!isAwaitAllowedInNode(parent)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The part above this looks unnecessarily opaque to me. Can it be simplified and/or explained (e.g., "we allow await …; expression statements and identifierName = await …; assignments, but not update-assignment like identifierName += await …; or nesting in other structures such as array/object literals or argument lists")?

Copy link
Member Author

@michaelfig michaelfig Mar 27, 2023

Choose a reason for hiding this comment

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

I've added a comment explaining this function's allowlist.

Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

I find the logic suggestions Richard made easier to follow. I'll approve after those are resolved.

Comment on lines 21 to 24
valid: clearlyBalanced,
// `no-nested-await` is not smart enough to ignore subtle code that is
// actually balanced. We test that it fails these cases.
invalid: [...clearlyUnbalanced, ...subtlyBalanced].map(example => ({
Copy link
Member

Choose a reason for hiding this comment

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

I appreciate the comment. Especially on subtlyBalanced in the other file. What the comment here says may be obvious if the names were mapped to this "smart enough" aspect:

Suggested change
valid: clearlyBalanced,
// `no-nested-await` is not smart enough to ignore subtle code that is
// actually balanced. We test that it fails these cases.
invalid: [...clearlyUnbalanced, ...subtlyBalanced].map(example => ({
valid: trueValid,
invalid: [...trueInvalid, ...falseInvalid].map(example => ({

Copy link
Member Author

@michaelfig michaelfig Mar 27, 2023

Choose a reason for hiding this comment

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

I like clearly* vs subtly*, but I agree that *Balanced vs. *Unbalanced should be *Valid vs. *Invalid.

@michaelfig michaelfig force-pushed the mfig-lint-nonnested-first-await branch from 6f83ac2 to b85546b Compare March 27, 2023 18:11
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

🎉

Excited to see the overzealous warnings in agoric-sdk go away :)

@michaelfig michaelfig merged commit e831045 into main Mar 27, 2023
@michaelfig michaelfig deleted the mfig-lint-nonnested-first-await branch March 27, 2023 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants