Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ota-meshi
Copy link
Member

No description provided.

Copy link

changeset-bot bot commented Sep 10, 2025

🦋 Changeset detected

Latest commit: 70bbe35

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 Patch

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

@ota-meshi ota-meshi marked this pull request as draft September 10, 2025 01:36
Copy link
Contributor

github-actions bot commented Sep 10, 2025

Try the Instant Preview in Online Playground

ESLint Online Playground

Install the Instant Preview to Your Local

npm i https://pkg.pr.new/eslint-plugin-svelte@70bbe35

Published Instant Preview Packages:

View Commit

@baseballyama
Copy link
Member

This is exactly the kind of implementation I had in mind for managing visited nodes.

@marekdedic
Copy link
Contributor

Thanks for the quick PR. My thoughts comparing it to #1344:

  • This would be easier to understand than the ASTSearchHelper
  • If I understand it correctly, the new function would track all nodes visited from the calling function (hence why it's the first parameter)
    • Do we need to clean up the set in order for it now to grow enormously on large codebases?
    • What if we call findVariable from the same function multiple times?
  • The findVariable function is already re-implemented in this package, so maybe we wouldn't even need findVaraibleSafe and could just change findVariable? Then we also wouldn't need the internal rule.
  • In the previous PR, I was going for a more general pattern inspired by the ReferenceTracker from eslint-utils. I still think something like that would make sense, but I agree that it would be better to separate it from the findVariable recursion issue.
  • Is there any other way we could get an infinite loop? The previous PR was in that sense more general and would prevent recursion through any means. But I can't think of another way right now.

@ota-meshi ota-meshi marked this pull request as ready for review September 10, 2025 13:13
@ota-meshi ota-meshi changed the title PoC: preventing infinite loops idea preventing infinite loops Sep 10, 2025
@ota-meshi
Copy link
Member Author

At least nobody is opposed to this change, so I'll mark it as ready.

  • The findVariable function is already re-implemented in this package, so maybe we wouldn't even need findVaraibleSafe and could just change findVariable? Then we also wouldn't need the internal rule.

Yeah, I think it's worth considering. In this PR, I wanted to minimize the difference and check that it can be checked with an internal custom rule.

  • In the previous PR, I was going for a more general pattern inspired by the ReferenceTracker from eslint-utils. I still think something like that would make sense, but I agree that it would be better to separate it from the findVariable recursion issue.

In my experience, I don't think the internal implementation of ReferenceTracker is very common in normal rule implementations. In other words, I currently think that maintaining the current implementation method as much as possible will make it easier for people with experience with eslint-plugins other than eslint-plugin-svelte to follow.

Is there any other way we could get an infinite loop? The previous PR was in that sense more general and would prevent recursion through any means. But I can't think of another way right now.

In my experience, I've never seen an infinite recursion issue like this outside of identifier tracking.


This PR owes a lot to your PR #1338, which gave me a lot of inspiration. Thank you so much!

@@ -1,5 +1,12 @@
import * as myPlugin from '@ota-meshi/eslint-plugin';
import * as tseslint from 'typescript-eslint';
import { createJiti } from 'jiti';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is jiti really needed here? I don't understand this much, but why not just import the rule straight away?

Copy link
Member Author

Choose a reason for hiding this comment

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

The rule is implemented in Typescript, so we need to import them via jiti. This will no longer be necessary once we drop support for older Node.

import type { TSESTree } from '@typescript-eslint/types';
import type { Variable } from '@typescript-eslint/scope-manager';

export default {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd still prefer just merging findVariableSafe into findVariable. Then the whole complication with this, and jiti can go away. And if I understand correctly, it's entirely possible, especially if we switch to marker: Symbol or marker: string.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's redundant to have more arguments that we won't use.
So I think it's better to leave it as it is.

@ota-meshi
Copy link
Member Author

When I was testing this, I found that the second lookup to the same identifier node (which is not recursive) returned null, which didn't work 😓
I'll think of a way to solve the problem.

@ota-meshi
Copy link
Member Author

I've done a major rewrite to solve the problem.
It's now handled in a pretty basic way.
I think this is easier than having to pass around a set of identifiers.

Copy link
Member

@baseballyama baseballyama left a comment

Choose a reason for hiding this comment

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

Thank you!

@baseballyama baseballyama changed the title preventing infinite loops fix: preventing infinite loops Sep 13, 2025
@baseballyama baseballyama merged commit 03a93f4 into main Sep 13, 2025
17 checks passed
@baseballyama baseballyama deleted the add-findVariableSafe-utlity branch September 13, 2025 01:19
@marekdedic
Copy link
Contributor

@ota-meshi
Copy link
Member Author

Yeah, if there is no recursion it will not be reported.

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