Skip to content

feat: add svelte/Infinite-reactive-loop rule #332

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 13 commits into from
Feb 6, 2023

Conversation

baseballyama
Copy link
Member

close: #299

@changeset-bot
Copy link

changeset-bot bot commented Dec 29, 2022

🦋 Changeset detected

Latest commit: 336dfa1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@baseballyama baseballyama force-pushed the feature/infinite-reactive-loop branch from d60b044 to 7f84429 Compare December 29, 2022 07:09
@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 29, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

}

$: (() => {
// TODO: This is a false positive. we need to check if the `then` or `catch` is `Promise` object's function.
Copy link
Member Author

Choose a reason for hiding this comment

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

@ota-meshi

I need your help!
I wanted to check that then or catch came from Promise type, but I couldn't find a way.
Could you please tell me?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's difficult to strictly check whether it's a Promise object or not. However, it's mostly okay to consider objects with then and catch methods that take functions as parameters to be Promises.
Other popular plugins also judge that way.

It's clearly a false positive in this test case, but I think we can consider that people don't do it.

@baseballyama baseballyama marked this pull request as ready for review December 29, 2022 07:58
@baseballyama baseballyama changed the title [WIP] feat: add svelte/Infinite-reactive-loop rule feat: add svelte/Infinite-reactive-loop rule Dec 29, 2022
@baseballyama
Copy link
Member Author

@ota-meshi What do you think about the current specification and implementation? Do you think there are TODOs?

@ota-meshi
Copy link
Member

I misunderstood that this PR was still in the work in progress 😓. I will make time to check this PR. So please wait 🙏

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me, but I think using a scopeManager allows we to use already parsed variables and reduce we own traversal.


// Promise.then() or Promise.catch() is called.
if (isPromiseThenOrCatchBody(node)) {
isSameMicroTask = true
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove the duplicate code by keeping the node when it changes to isSameMicroTask = false in enterNode() so that when the same node comes, isSameMicroTask = true. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I removed the duplicate code.

336dfa1

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@ota-meshi ota-meshi merged commit 26870cf into sveltejs:main Feb 6, 2023
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.

svelte/Infinite-reactive-loop
2 participants