Comments (15)
This also happens for a custom store (in my case secret
or $secret
) as well.
Also Svelte 5, Eslint, TS.
from eslint-plugin-svelte.
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.
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.
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.
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.
@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.
I'm running into this as well.
from eslint-plugin-svelte.
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.
Is it possible to disable this error?
from eslint-plugin-svelte.
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.
I tried adding page as a global in eslint config
no luck
not a big deal though
from eslint-plugin-svelte.
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.
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.
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.
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)
- Suggestion: Override `init-declarations`
- Svelte 5: Parsing Error with Snippets
- Add option to svelte/prefer-class-directive - apply only when one side is the empty string HOT 2
- Apply `@typescript-eslint/no-misused-promises` to Svelte components HOT 1
- svelte eslint is parsing script tags in @html string literals
- Incorrect no-undef and @typescript-eslint/no-unused-vars errors for Svelte 5 Snippets
- Ship types for `eslint-define-config`
- Type inferred as `any` in `.svelte` file. HOT 1
- bun install fails for complex dependency version HOT 4
- Component type is inferred as any HOT 1
- ESLint Flat config HOT 8
- ESLint 9 support HOT 3
- Release of v2.36.0
- Linting with flat config (ESLint 9) does not work with TypeScript HOT 29
- Svelte 5 - "illegal variable name" when using stores HOT 1
- New rule: `no undefined variable in the DOM` HOT 6
- Migrate the docs to Svelte 5 HOT 2
- Clean up configs HOT 1
- Using stores causes an error in `svelte/valid-compile` HOT 1
- Add svelte/attributes-line-break HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-svelte.