Skip to content

Add rule no-goto-without-base #675

Closed
@marekdedic

Description

@marekdedic

Motivation

In SvelteKit, the goto function is used for internal navigation. That means, that you basically almost always want to prefix the url with the base path.

Description

Add a rule that would trigger on any goto without a base path. However, there are quite some edge cases

Examples

<script>
  import { base } from "$app/paths";
  import { base as whatever } from "$app/paths";
  import { goto } from "$app/navigation";

  <!--GOOD -->
  goto(base + "/foo");
  goto(`${base}/foo`)
  goto(whatever + "/foo");
  goto(`${whatever}/foo`)
  goto("https://absolute.url");

  <!--BAD -->
  goto("/foo");
  goto("foo/" + base);
  goto(`foo/${base}`);
</svelte>

Additional comments

Is this plugin the right place to put SvelteKit rules?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions