sveltejs / eslint-plugin-svelte

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

reactive_declaration_non_reactive_property is considered error instead of warning #896

Open fev4 opened 1 day ago

fev4 commented 1 day ago

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

What version of ESLint are you using?

9.13.0

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

2.46.0

What did you do?

Configuration ``` import js from '@eslint/js'; import ts from 'typescript-eslint'; import svelte from 'eslint-plugin-svelte'; import prettier from 'eslint-config-prettier'; import globals from 'globals'; // /** @type {import('eslint').Linter.FlatConfig[]} */ export default [ js.configs.recommended, ...ts.configs.recommended, ...svelte.configs['flat/recommended'], prettier, ...svelte.configs['flat/prettier'], { languageOptions: { globals: { ...globals.browser, ...globals.node, }, }, rules: { '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-unused-vars': [ 'warn', { varsIgnorePattern: '^\\$\\$(Props|Events|Slots|Generic)$' }, ], }, }, { files: ['**/*.svelte'], languageOptions: { parserOptions: { parser: ts.parser, }, }, }, { ignores: [ '.env', '.env.*', '!.env.example', '/static/assets/fa', '.DS_Store', '/package', 'build/', '.svelte-kit/', 'dist/', 'pnpm-lock.yaml', 'package-lock.json', 'yarn.lock.DS_Store', '.pnpm-debug.log', 'node_modules', 'vite.config.ts.timestamp-*', 'playwright-report/**', ], }, ]; ```
  $: initial = {
    envelope_id,
    account_id: $envelope?.account_id,
    type:
      TransactionType.INFLOW == type
        ? TransactionType.INFLOW
        : TransactionType.OUTFLOW,
    amount: Number(amount),
  };

TransactionType is an enum and all it's properties have this warning when used inside $: (we haven't started migration to Svelte 5 runes yet.

Properties of objects and arrays are not reactive unless in runes mode. Changes to this property will not cause the reactive statement to updatesvelte(reactive_declaration_non_reactive_property)

Then ran:

pnpm exec eslint .

What did you expect to happen?

I was expecting this to not be an error and instead a warning.

What actually happened?

/src/routes/app/create-envelope-transaction/+page.svelte
  16:7   error  Properties of objects and arrays are not reactive unless in runes mode. Changes to this property will not cause the reactive statement to update(reactive_declaration_non_reactive_property)  svelte/valid-compile
  17:11  error  Properties of objects and arrays are not reactive unless in runes mode. Changes to this property will not cause the reactive statement to update(reactive_declaration_non_reactive_property)  svelte/valid-compile
  18:11  error  Properties of objects and arrays are not reactive unless in runes mode. Changes to this property will not cause the reactive statement to update(reactive_declaration_non_reactive_property)  svelte/valid-compile

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/fev4/reactive-non-reactive

Additional comments

When I try to ignore it with the following it persists, which makes sense since these are two different tools (one is the Svelte VSCode extension and the other ESLint):

// svelte-ignore reactive_declaration_non_reactive_property
fev4 commented 20 hours ago

After thoroughly testing I seem to have found that the error steamed from an bogus node_modules (deleting and installing again seems to have fixed the issue). I'm closing this as I'm not able to reproduce in the MRE.

Error persists, please read the next comment.

fev4 commented 20 hours ago

I was thinking about this the wrong way. It's not related to node_modules, it just a different behavior between pnpm check and pnpm eslint .. The first one throws warnings as expected but pnpm eslint . throws the errors which is the unexpected part. The reason I was confused is that we have a custom formatter and it was using pnpm eslint . under the hood instead of directly pnpm check.

Here`s the MRE: https://github.com/fev4/reactive-non-reactive

I'm going to reopen this issue as I believe it's an inconsistency.