sveltejs / eslint-plugin-svelte

ESLint plugin for Svelte using AST
https://sveltejs.github.io/eslint-plugin-svelte/
MIT License
276 stars 29 forks source link

Svelte 5: compiler's "warn" is reported as "error" by the plugin #764

Closed qupig closed 1 month ago

qupig commented 1 month ago

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

What version of ESLint are you using?

9.3.0

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

2.39.0

What did you do?

Configuration import eslintPluginSvelte from 'eslint-plugin-svelte'; export default [ ...eslintPluginSvelte.configs['flat/recommended'], ];

Check the console output of the following commands in StackBlitz-Demo.

// "reproduce": "vite build && eslint ."
npm run reproduce

Also in Svelte5-REPL.

What did you expect to happen?

"eslint-plugin-svelte" should report the same error level as the svelte compiler.

What actually happened?

❯ npm run build

> vite-svelte-starter@0.0.0 build
> vite build

3:57:34 PM [vite-plugin-svelte] You are using Svelte 5.0.0-next.143. Svelte 5 support is experimental, breaking changes can occur in any release until this notice is removed.
work in progress:
 - svelte-inspector is disabled until dev mode implements node to code mapping

vite v5.2.12 building for production...
transforming (1) index.html3:57:35 PM [vite-plugin-svelte] src/App.svelte:6:5 `constVar` is updated, but is not declared with `$state(...)`. Changing its value will not correctly trigger updates (warn)
✓ 76 modules transformed.
dist/index.html                 0.46 kB │ gzip: 0.30 kB
dist/assets/index-DPDjIYFo.css  1.00 kB │ gzip: 0.54 kB
dist/assets/index-DuTKyy1k.js   7.24 kB │ gzip: 3.29 kB
✓ built in 465ms

~/projects/vitejs-vite-snxrvp 3s

❯ npm run eslint

> vite-svelte-starter@0.0.0 eslint
> eslint .

/home/projects/vitejs-vite-snxrvp/src/App.svelte
  6:6  error  `constVar` is updated, but is not declared with `$state(...)`. Changing its value will not correctly trigger updates(non_reactive_update)  svelte/valid-compile

✖ 1 problem (1 error, 0 warnings)

Link to GitHub Repo with Minimal Reproducible Example

This is easy to reproduce, everything is configured as default.

If you don't want to fix it, feel free, I'm reporting this issue for the third time.

Sorry, I don't have more time to make a GitHub repository for you.

(Also, please don’t ask for "minimal reproduction" TWICE in the issue template and demand for the GitHub Repo the second time!)

Additional comments

Related issue: https://github.com/sveltejs/svelte/issues/11818

baseballyama commented 1 month ago

I think just you can override ESLint config. e.g.

import eslintPluginSvelte from 'eslint-plugin-svelte';

export default [
  // https://github.com/sveltejs/eslint-plugin-svelte
  ...eslintPluginSvelte.configs['flat/recommended'],
  {
    rules: {
      'svelte/valid-compile': 'warn',
    },
  },
];
qupig commented 1 month ago

Why does the plugin report higher level errors than the svelte compiler? Why not use the same warning level?

baseballyama commented 1 month ago

recommended config is just recommended rule set. Feel free to change the settings if you are unhappy with them in you eslint config file.

The Svelte compiler sometimes uses the warning level because it also need to consider about backwards compatibility and other considerations.

qupig commented 1 month ago

So what you mean is that the plugin's ruleset can only report an error to eslint and not a warn?

Or is the rule set unable to distinguish between different levels of warn/error in that svelte/valid-compile set?

So the question is, is lowering the level of the entire svelte/valid-compile set for this particular warn the only option?

UPDATE: Forget about it, it's always possible to add ugly comments to line: // eslint-disable-next-line svelte/valid-compile

Otherwise shouldn't the plugin be passed to eslint the same warning level produced by the svelte compiler?

baseballyama commented 1 month ago

The svelte compiler throws an error when the code can not compile. ESLint throws an error when a user wants to throw.

The semantics of error differs between the Svelte compiler and ESLint.

shouldn't the plugin be passed to eslint the same warning level produced by the svelte compiler?

This is possible within the ESLint plugin code, but users can not do fine-grained configure. So, at present, everything is set to error/warn.

If there is a problem, you should disable the ESLint rule and make the warning from the Svelte compiler an error, which can be achieved with the onwarn option in vite-plugin-svelte.

https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#config-file