Skip to content

New Rule: svelte/no-dupe-on-directives and svelte/no-dupe-use-directives #304

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

Closed
ota-meshi opened this issue Nov 24, 2022 · 0 comments · Fixed by #308
Closed

New Rule: svelte/no-dupe-on-directives and svelte/no-dupe-use-directives #304

ota-meshi opened this issue Nov 24, 2022 · 0 comments · Fixed by #308
Labels
enhancement New feature or request new rule

Comments

@ota-meshi
Copy link
Member

Motivation

We can define any number of on: and use: directives with the same name, but duplicate directives with the exact same name and expression are probably a mistake.
I would like to find it in the new rule.

See also sveltejs/svelte#8048.

Description

The new rule reports on: directives with exactly the same name and expression, and use: directives with exactly the same name and expression.

Examples

<!-- ✓ GOOD -->
<button on:click on:click={myHandler}  />
<button on:click={foo} on:click={bar}  />
<div use:clickOutside use:clickOutside={param}  />
<div use:clickOutside={foo} use:clickOutside={bar} />

<!-- ✗ BAD -->
<button on:click on:click />
<button on:click={myHandler} on:click={myHandler} />
<div use:clickOutside use:clickOutside  />
<div use:clickOutside={param} use:clickOutside={param}  />

Additional comments

As for on:, maybe some users want to report even if the expression is different. I think we can add an option to the rule in that case.

<!-- maybe BAD? -->
<button on:click={foo} on:click={bar}  />

<!-- GOOD? -->
<script>
function handler(evt) {
  foo(evt);
  bar(evt);
}
</script>
<button on:click={handler} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule
Projects
None yet
1 participant