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

A11y warnings do not account for destructured attributes. #9142

Closed
emmbm opened this issue Aug 24, 2023 · 3 comments
Closed

A11y warnings do not account for destructured attributes. #9142

emmbm opened this issue Aug 24, 2023 · 3 comments
Milestone

Comments

@emmbm
Copy link

emmbm commented Aug 24, 2023

Describe the bug

I haven't tested with different cases yet, but assigning an anchor tag's href using a destructured object does not appear to mitigate missing attribute warnings.

Reproduction

For illustration:

<script lang="ts">
  const attributes = {
    href: '/about'
  }
</script>

<nav>
  <a {...attributes}>About</a> <!-- A11y: <a> element should have an href attributesvelte(a11y-missing-attribute) -->
</nav>

Cases like the above will quickly be met when using an approach similar to melt-ui's builders to manage an element's attributes. For example, in my app I have a series of small i18n helpers that localize anchor hrefs (prepending the locale param) and specify their corresponding hreflang attribute:

<nav>
  <a {...$i18nlink('/about')}>{t('about')}</a> <!-- A11y: <a> element should have an href attributesvelte(a11y-missing-attribute) -->
  <a href={$i18nhref('/projects')} hreflang={$page.data.locale}>{t('projects')}</a>
</nav>

where i18nlink is a derived store returning an object {href: string, hreflang: string}.

Expected behaviour

If destructured object used for element attributes contains expected attribute keys (for example href on an anchor tag), omit warning.

System Info

  • OS: MacOS
  • IDE: VSCode

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

@emmbm emmbm added the bug label Aug 24, 2023
@dummdidumm dummdidumm transferred this issue from sveltejs/language-tools Aug 24, 2023
@Conduitry
Copy link
Member

We're not, in general, going to be able to tell at compile time whether a given attribute is going to be present. I guess the question, then, is whether we ought to disable all missing-attribute a11y warnings for a given element when it has spread attributes. And I don't know what my answer is to that.

@geoffrich
Copy link
Member

My vote would be to not throw the warning if the element has a spread attribute. In the past we've seemed to opt for false negatives over false positives and this would be in line with that.

@dummdidumm
Copy link
Member

This will no longer throw a warning in Svelte 5

@dummdidumm dummdidumm added this to the 5.x milestone Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants