eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

Rule suggestion: Ensure that route params type is string or number

Open MartJohan opened this issue 1 year ago • 0 comments

Please describe what the rule should do: This new rule should check if the params passed when using either router-link in the template or the programmatic variation router.push({}) have different types than string and/or number. Currently vue-router throws a warning that the params gets discarded because that way of routing is an anti-pattern, description can be found here.

What category should the rule belong to?

[ ] Enforces code style (layout) [X ] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

import useRouter from 'vue-router'

const router = useRouter()
const user = { name: 'Evan', surname: 'You'};

function navigate() {
   router.push({ name: 'users.list', params: { user } })
}
import useRouter from 'vue-router'

const router = useRouter()
const user = { name: 'Evan', surname: 'You'};

<template>
    <router-link :to={ name: 'users.list', params: { user } }>
         Edit user
    </router-link>
</template>
import useRouter from 'vue-router'

const router = useRouter()
const user = { name: 'Evan', surname: 'You'};

<template>
    <router-link :to={ name: 'users.list', params: { user, isAuthenticated: true } }>
         Edit user
    </router-link>
</template>

Additional context Even though there is a warning coming from vue-router about the params it would still be nice to get the warning before having to build the project.

MartJohan avatar Nov 09 '23 08:11 MartJohan