Giter Site home page Giter Site logo

Comments (15)

lyssieth avatar lyssieth commented on June 18, 2024 16

This also happens for a custom store (in my case secret or $secret) as well.

Also Svelte 5, Eslint, TS.

from eslint-plugin-svelte.

ryanatkn avatar ryanatkn commented on June 18, 2024 8

The get proposal is also unsuitable as a general workaround because it's non-reactive. It subscribes and immediately unsubscribes, whereas $ subscribes and doesn't unsubscribe until the component is destroyed.

from eslint-plugin-svelte.

RyousukeUchino avatar RyousukeUchino commented on June 18, 2024 7

@christophsturm @huntabyte

I'm not entirely sure if this is correct, but I was able to find a workaround using the following method:

<script lang="ts">
  import { page } from '$app/stores';
  import { get } from 'svelte/store';

  const currentPagePath = get(page).url.pathname;
  const currentPageData = get(page).data
</script>
{#if currentPagePath === '/store'}
  hoge fuga
{/if}

from eslint-plugin-svelte.

Conduitry avatar Conduitry commented on June 18, 2024 5

This plugin appears to be incorrectly transforming the <script> tag (perhaps via TypeScript?) before passing it to the compiler.

Something like

<script>
	import { page } from '$app/stores';
</script>

is getting transformed into

<script>import '$app/stores';
//# sourceMappingURL=module.js.map
</script>

presumably because it's only operating on the <script> tag and it thinks page is unused and it's safe to turn that into a bare import '$page/stores'.

Putting a bare reference to page; in the <script> tag seems to be a workaround for the time being.

<script>
	import { page } from '$app/stores';
	page;
</script>

gets transformed into

<script>import { page } from '$app/stores';
page;
//# sourceMappingURL=module.js.map
</script>

but the real solution is going to be fixing this transformation that the plugin does to the script tag before passing it to the Svelte compiler. If this is related to TypeScript, I think the solution is going to be to just stop running the <script> tag through TypeScript in Svelte 5, because that should be already handled by the Svelte compiler.

from eslint-plugin-svelte.

jill64 avatar jill64 commented on June 18, 2024 4

@unlocomqx

The following can be used as a workaround

Disable in one line

<script>
  import { page } from '$app/stores';

  // eslint-disable-next-line svelte/valid-compile
  const currentPagePath = $page.url.pathname;
</script>

Disable in project

.eslintrc.cjs

module.exports = {
  // ...
  rules: {
    "svelte/valid-compile": "off"
  }
}

Check here for additional details
https://eslint.org/docs/latest/use/configure/rules

from eslint-plugin-svelte.

Conduitry avatar Conduitry commented on June 18, 2024 4

@dummdidumm In Svelte 5, is there a reason to transpile the <script> tag at all before passing it to the Svelte compiler, though?

from eslint-plugin-svelte.

niemyjski avatar niemyjski commented on June 18, 2024 2

I'm running into this as well.

from eslint-plugin-svelte.

christophsturm avatar christophsturm commented on June 18, 2024

is there a workaround? btw, where is the source of the next plugin, in case i want to work on a PR

from eslint-plugin-svelte.

unlocomqx avatar unlocomqx commented on June 18, 2024

Is it possible to disable this error?

from eslint-plugin-svelte.

jill64 avatar jill64 commented on June 18, 2024

As you may already know, the @RyousukeUchino proposal may suppress warnings, but is not recommended in hot code paths.

https://svelte.dev/docs/svelte-store#get

This works by creating a subscription, reading the value, then unsubscribing. It's therefore not recommended in hot code paths.

from eslint-plugin-svelte.

unlocomqx avatar unlocomqx commented on June 18, 2024

I tried adding page as a global in eslint config
no luck

not a big deal though

from eslint-plugin-svelte.

dummdidumm avatar dummdidumm commented on June 18, 2024

From @Conduitry's investigation my shot in the dark is that ts.transpileModule (or whatever the low level transpiration API is called) is called with the wrong config, where imports are not left alone and instead "treeshaken". verbatimModuleSyntax was introduced for this reason in TS and is the recommended default since TS 5.0, and leaves imports as is.

from eslint-plugin-svelte.

rChaoz avatar rChaoz commented on June 18, 2024

I don't think so, the Svelte 5 compiler natively supports Typescript (now even in the template, not just the script tag).

from eslint-plugin-svelte.

ptrxyz avatar ptrxyz commented on June 18, 2024

I tried setting verbatimModuleSyntax to true, but it doesn't seem to have an effect. So yes, probably it is using a wrong configuration. :/

from eslint-plugin-svelte.

Alia5 avatar Alia5 commented on June 18, 2024

I don't think so, the Svelte 5 compiler natively supports Typescript (now even in the template, not just the script tag).

It doesn't fully support all TS features, decorators and enums among them, so there might still be a need to preproccess the files beforehand.

from eslint-plugin-svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.