sveltejs / eslint-plugin-svelte

ESLint plugin for Svelte using AST
https://sveltejs.github.io/eslint-plugin-svelte/
MIT License
277 stars 30 forks source link

Add rule `no-goto-without-base` #675

Closed marekdedic closed 4 months ago

marekdedic commented 5 months ago

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?

ota-meshi commented 5 months ago

Thank you for posting proposed rule!

Is this plugin the right place to put SvelteKit rules?

I think it's good that the rules regarding what svelte official provides are provided by this plugin.