New Rule: svelte/valid-context-access

#448

Development PR

Issue

Open
B
baseballyama
Apr 26, 2023, 8:07 AM

Motivation

This is came from sveltejs/svelte#7864

Description

According to the docs, getContext needs to call during component initialization. Svelte team tried to implement this in the compiler, but this is a bit difficult, so I thought that we will implement this as ESLint rule.

https://svelte.dev/docs#run-time-svelte-getcontext

Retrieves the context that belongs to the closest parent component with the specified key. Must be called during component initialisation.

Examples

<script>
  import { getContext } from 'svelte';

  let test = getContext('test');
</script>



<!-- ✓ GOOD -->
<a href={test}>xxx</a>

<!-- ✗ BAD -->
<a href={getContext('test')}>xxx</a>

Additional comments

No response

👍 2

Info

Assignees None
Labels enhancement, new rule
Milestone post-v3