Skip to content

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

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy