Skip to content

Conversation

marekdedic
Copy link
Contributor

Hi, I added a fix for #1337 and the issues with no-navigation-without-resolve (and its deprecated variants) mentioned in #1322

I also checked the rest of the codebase for similar risky patterns and converted several places where it seemed useful or would clean up the code, please take a look and let me know if it makes sense.

Copy link

changeset-bot bot commented Sep 9, 2025

🦋 Changeset detected

Latest commit: 407a1c8

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

Copy link
Contributor

github-actions bot commented Sep 9, 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@407a1c8

Published Instant Preview Packages:

View Commit

@marekdedic marekdedic force-pushed the consistent-selector-style-infinite-loop-fix branch 2 times, most recently from 563a4c8 to b05ce6b Compare September 9, 2025 17:08
@marekdedic marekdedic marked this pull request as draft September 9, 2025 17:09
@marekdedic marekdedic force-pushed the consistent-selector-style-infinite-loop-fix branch 3 times, most recently from 9c24dd3 to 82b3e76 Compare September 9, 2025 17:20
@marekdedic marekdedic marked this pull request as ready for review September 9, 2025 17:24
) => T | null;
};

export function ASTSearchHelper<T>(startNode: ASTNode, nodeResolvers: NodeResolvers<T>): T | null {
Copy link
Member

Choose a reason for hiding this comment

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

What is the use of this function? I don't understand it. Can you explain?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is the core of this PR. It abstracts away a common pattern where you search through the AST and depending on the node you return some value or look in another node (usually parent, child, but also e.g. variable definition).

As we noticed in the linked PR, there is an issue in both consistent-selector-style as well as no-navigation-without-resolve where you could get an infinite recursion in the rule code.

This function prevents infinite loops as well. The pattern seemed to repeat in multiple places in the codebase, so I created this abstraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re: no-dynamic-slot-name - Ugh, that's not in the tests, could you add it? The playground doesn't work for me.

Since the rule is deprecated, my first choice would be to leave it as it is and remove the change to this rule, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

This function prevents infinite loops as well. The pattern seemed to repeat in multiple places in the codebase, so I created this abstraction.

So that's not working right now, right?

Copy link
Member

Choose a reason for hiding this comment

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

Since the rule is deprecated, my first choice would be to leave it as it is and remove the change to this rule, what do you think?

I think it would be a good idea to refactor the deprecation rules as well, to test whether the new functions work well.

Copy link
Member

Choose a reason for hiding this comment

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

The playground doesn't work for me.

Try testing it with the following file:

<script>
  /* eslint svelte/no-dynamic-slot-name: "error" */
  const f = SLOT_NAME;
  const SLOT_NAME = f;
</script>

<!-- ✓ GOOD -->
<slot name="good" />

<!-- ✗ BAD -->
<slot name={SLOT_NAME} />

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, with the test case I was able to fix that rule as well :)

@marekdedic marekdedic force-pushed the consistent-selector-style-infinite-loop-fix branch from 82b3e76 to 407a1c8 Compare September 9, 2025 23:42
@ota-meshi
Copy link
Member

I don't think the new function makes maintenance easier.
I think the purpose is to prevent infinite recursion with findVariable(), but I think there's a lot more that can be done with the function.
In other words, I don't think other contributors would understand how to use ASTSearchHelper or when to use it.

Instead, could you/we add a helper that prevents recursive calls to findVariable()?
If we could do that, we could prevent incorrect usage with an eslint rule that disallows direct calls to findVariable().

@ota-meshi
Copy link
Member

What do you think of this idea? #1344

@ota-meshi
Copy link
Member

In respect of #1344, this PR will be closed. Thank you!

@ota-meshi ota-meshi closed this Sep 10, 2025
@marekdedic marekdedic deleted the consistent-selector-style-infinite-loop-fix branch September 10, 2025 15:13
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.

2 participants