Skip to content

False positive "require-store-reactive-access" when returning context or readable #1424

@echocrow

Description

@echocrow

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?

9.39.1

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

3.12.4

What did you do?

Configuration
// Created via `sv`
import { fileURLToPath } from 'node:url';
import { includeIgnoreFile } from '@eslint/compat';
import js from '@eslint/js';
import svelte from 'eslint-plugin-svelte';
import { defineConfig } from 'eslint/config';
import globals from 'globals';
import ts from 'typescript-eslint';
import svelteConfig from './svelte.config.js';

const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));

export default defineConfig(
	includeIgnoreFile(gitignorePath),
	js.configs.recommended,
	...ts.configs.recommended,
	...svelte.configs.recommended,
	{
		languageOptions: {
			globals: { ...globals.browser, ...globals.node }
		},
		rules: { // typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.
		// see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
		"no-undef": 'off' }
	},
	{
		files: [
			'**/*.svelte',
			'**/*.svelte.ts',
			'**/*.svelte.js'
		],
		languageOptions: {
			parserOptions: {
				projectService: true,
				extraFileExtensions: ['.svelte'],
				parser: ts.parser,
				svelteConfig
			}
		}
	}
);

<script lang="ts">
import {getContext} from 'svelte'
import {type Readable, readable} from 'svelte/store'

export function getStore(): Readable<Record<string, unknown>> {
  return getContext('some_key') ?? readable({})
}
</script>

What did you expect to happen?

Lint passes

What actually happened?

  6:10  error  Use the $ prefix or the get function to access reactive values instead of accessing the raw store  svelte/require-store-reactive-access

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/echocrow/eslint-plugin-svelte-repro--false-positive-reactive-store

Additional comments

Not getting this error when e.g. removing the return type of getStore(), or swapping getContext(..) with a bogus implementation. ¯\_(ツ)_/¯

May be related to #1312?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions