Skip to content

New Rule: svelte/valid-context-access #448

Open
@baseballyama

Description

@baseballyama

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions