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

Add rule no-useless-children-snippet #909

Open
marekdedic opened this issue Nov 8, 2024 · 2 comments · May be fixed by #922
Open

Add rule no-useless-children-snippet #909

marekdedic opened this issue Nov 8, 2024 · 2 comments · May be fixed by #922
Labels

Comments

@marekdedic
Copy link
Contributor

Motivation

Any content inside a component tag becomes the children snippet. Thus, If you have a component with a children snippet without parameters, that's unnecessary.

Description

I'd like to add a rule that bans the children snippet if it has no parameters

Examples

<script>
</script>

<!-- ✓ GOOD -->
<Foo>
  {#snippet bar()}
    Hello
  {/snippet}
</Foo>

<Foo>
  {#snippet children(val)}
    Hello {val}
  {/snippet}
</Foo>

<Foo>
  Hello
</Foo>

<!-- ✗ BAD -->
<Foo>
  {#snippet children()}
    Hello
  {/snippet}
</Foo>

Additional comments

No response

@ota-meshi
Copy link
Member

Thank you for proposing the rule. SGTM!

Maybe the rule should be a bit clearer. For example, how about the name no-useless-children-snippet?
I think the rule name might confuse users if we later create a rule to report components like this:

{#snippet foo(value)}
  Hello {value}
{/snippet}

<!-- ✗ BAD -->
<Foo>
  {#snippet bar(value)}
    {@render foo(value)}
  {/snippet}
</Foo>

<!-- ✓ GOOD -->
<Foo bar={foo}>
</Foo>

@marekdedic
Copy link
Contributor Author

Makes sense, renaming! Thanks :)

@marekdedic marekdedic changed the title Add rule no-useless-snippet Add rule no-useless-children-snippet Nov 18, 2024
@marekdedic marekdedic linked a pull request Nov 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants