Skip to content

Destructured store values are seen as unused/undefined #188

@tivac

Description

@tivac

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.15.10

What version of eslint-plugin-svelte are you using?

2.2.0

What did you do?

Configuration
"no-undef" : "error",
"svelte/valid-compile" : [ "error", {
	// We do some stuff that goes against web a11y best practices, because
	// we're not a website.
	ignoreWarnings : true,
}],

"svelte/no-unknown-style-directive-property" : [ "warn", {
	// These are special gameface-only properties, and svelte does the
	// right thing with them under the covers so let 'em through
	ignoreProperties : [
		"/\\w+PX$/",
	],
}],

"svelte/html-quotes" : [ "warn", {
	prefer : "double",
}],

"svelte/max-attributes-per-line" : [ "warn", {
	singleline : 3,
}],

"svelte/first-attribute-linebreak" : "warn",
"svelte/mustache-spacing" : "warn",
"svelte/prefer-style-directive" : "warn",
"svelte/no-useless-mustaches" : "warn",
"svelte/require-optimized-style-attribute" : "error",
"svelte/shorthand-attribute" : "warn",
"svelte/shorthand-directive" : "warn",
"svelte/spaced-html-comment" : "warn",
"svelte/no-inner-declarations" : "error",

// Disabled in favor of svelte-specific rule
"indent" : "off",
"svelte/indent" : [ "warn", {
	indent : "tab",
	indentScript : false,
}],
<script>
  import { readable } from "svelte/store";

  const bar = {
    foo : readable("hi"),
  };

  $: ({ foo } = $bar);

  $: baz = $foo;
</script>

{baz};

What did you expect to happen?

The destructured store is valid, and should be understood to be a reference to the non-$ prefixed variable.

What actually happened?

[13:9]: 'foo' is defined but never used. [(no-unused-vars)](https://eslint.org/docs/rules/no-unused-vars)
[15:12]: '$foo' is not defined. [(no-undef)](https://eslint.org/docs/rules/no-undef)

Link to Minimal Reproducible Example

https://ota-meshi.github.io/eslint-plugin-svelte/playground/#eJxFkMFuwyAQRH9linIAyTTu1XVy6qVf0Isv2N5UljBYsEmlWvx7wUlccVnNvNkdsYrBjyQa0b5ojS+yg58J7EHRTo71Yq/fk9PxRpYJWp8718YhTAvnCZjmxQfGikBmNL0lJFyCn9GJe+QY2QfqxHvnCj94Fxm9CThhLQJw8R7Nnpd1BRmJFU7nJ/GMTWNOZe/TMYWbsVJuVFbkh2F6df5HKlXhra5rVQ7y9h47AvE1ONwzgyUT9j3TWPACJVWVIT3qHhrIdWuY8ulcW/0bvfnN2iGbWWuP+6d0bs1WEukPJLxt1A==

Additional comments

Svelte REPL Repro of the code correctly subscribing to the destructured store.

Seems similar in some ways to #172 as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions