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

svelte eslint is parsing script tags in @html string literals #699

Open
2 tasks done
thesiti92 opened this issue Mar 6, 2024 · 0 comments
Open
2 tasks done

svelte eslint is parsing script tags in @html string literals #699

thesiti92 opened this issue Mar 6, 2024 · 0 comments

Comments

@thesiti92
Copy link

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.57.0

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

2.35.1

What did you do?

Configuration
extends: ["eslint:recommended", "plugin:svelte/recommended", "plugin:@typescript-eslint/recommended", "plugin:import/recommended", "plugin:import/typescript", "plugin:jest-formatting/strict", "prettier"],
	parser: "@typescript-eslint/parser",
	parserOptions: {
		project: "./tsconfig.json",
		extraFileExtensions: [".svelte"],
	},
	overrides: [
		{
			files: ["*.svelte"],
			parser: "svelte-eslint-parser",
			// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
			parserOptions: {
				parser: "@typescript-eslint/parser",
			},
		},
		{
			files: ["**/?(*.)+(spec|test).+(js|ts|svelte)"],
			plugins: ["vitest"],
			extends: ["plugin:vitest/recommended"],
			rules: {
				"vitest/consistent-test-it": ["error", { fn: "it" }],
			},
		},
	],
in a script block: ```js const x = `<script>var x = ${50}</script>` ```

in markup:

	{@html `<script>var x = ${50}</script>`}

What did you expect to happen?

svelte eslint to ignore the script block in the string literals. when the parent script is SSR'd the template literal is evaluated, so the underlying script is then valid.

What actually happened?

It seems like svelte-eslint is just looking for any script tag pair in the source files regardless of if its actual syntax or in a string literal.

Link to GitHub Repo with Minimal Reproducible Example

just paste those snippets into any svelte repo and itll break.

Additional comments

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant