Skip to content

define-macros-order: should allow referencing local variables defined before the macros statement #2746

Open
@andreww2012

Description

@andreww2012

What did you do?

define-macros-order should probably allow referencing local variables defined before the macros:

<script setup lang="ts">
/* eslint vue/define-macros-order: [2, {order: ["defineOptions", "defineModel", "defineProps", "defineEmits", "defineSlots"]}] no-use-before-define: 2 */
import {ref} from 'vue';

const lastSetModelValue = ref<string>();
// "defineModel should be the first statement in `<script setup>` (after any potential import statements or type definitions)",
// but it's not safe to move `lastSetModelValue` after the macros
const [modelValue, modelModifiers] = defineModel<string>({
  set: (value: string) => {
    lastSetModelValue.value = value;
    return value;
  },
  get: (value: string) => {
    return lastSetModelValue.value ?? value;
  },
});
</script>

What did you expect to happen?

The rule should not report .

If lastSetModelValue definition is moved below defineModel, no-use-before-define will be triggered as well as define-macros-order on the following macros definitions.

Repository to reproduce this issue

Reproduction

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions