vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.47k stars 666 forks source link

Allow specifying custom macros in `vue/define-macros-order` #2499

Closed Ericlm closed 2 months ago

Ericlm commented 4 months ago

What rule do you want to change? I would like to update the define-macros-order rule.

Does this change cause the rule to produce more or fewer warnings? More.

How will the change be implemented? (New option, new default behavior, etc.)? With the unplugging-vue-router which allows routes to be typesafe, there is now a new definePage macro that allows to customize the generated route.

I think this macro should be ordered just like defineProps, emits, slots etc. I think it could be at the top of the component, even before defineModel.

Please provide some example code that this change will affect:

<script setup lang="ts">
import { useRouter } from 'vue-router'

const router = useRouter()

definePage({}) // Can be placed anywhere

function hello(): void {
  router.push({ name: '/' })
}
</script>

What does the rule currently do for this code? The rule does not enforce a location for definePage, so it can be placed anywhere in the script.

What will the rule do after it's changed? It will enforce the definePage macro to be at the top of the script (or elsewhere).

FloEdelmann commented 4 months ago

Unplugin Vue Router will not be officially supported in eslint-plugin-vue, so this feature request is out of scope.

But you can already adjust the order manually. I think it should be possible to allow custom values there, so that you could add definePage there manually. Pull request welcome for that change!