Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force defineExpose at the end of <script> #2235

Closed
Thomasan1999 opened this issue Jul 12, 2023 · 7 comments · Fixed by #2349
Closed

Force defineExpose at the end of <script> #2235

Thomasan1999 opened this issue Jul 12, 2023 · 7 comments · Fixed by #2349

Comments

@Thomasan1999
Copy link

Please describe what the rule should do:

The rule would force to have defineExpose at the end of the <script> tag. When <script setup> is used, defineExpose is used as the alternative to return and is often expected to be at the end the same way return was. It also uses the data used in <script> and should therefore not be placed before the data itself. It is similar to vue/define-macros-order where define macros are forced at the beginning of <script>.

What category should the rule belong to?

[X] Enforces code style (layout)
[ ] 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:

<script setup>
const counter = ref(0);
const title = ref('');

defineExpose({
    counter,
    title,
});

const itemsText = computed(() => `${ counter.value } items`);
</script>

<script setup>
const counter = ref(0);
const title = ref('');

defineExpose({
    counter,
    title,
});

const shown = ref(false);

function show() {
    show.value = true;
}

watch(counter, show);
</script>

Additional context

@FloEdelmann
Copy link
Member

I think it could even be part of vue/define-macros-order with a new option. What do you think?

@Eternal-Rise

This comment was marked as off-topic.

@FloEdelmann

This comment was marked as off-topic.

@Eternal-Rise

This comment was marked as off-topic.

@FloEdelmann

This comment was marked as off-topic.

@J-Michalek
Copy link

I think it could even be part of vue/define-macros-order with a new option. What do you think?

I agree and would welcome defineExpose to be added to the vue/define-macros-order rule as I ran into issues when I tried to use it right away and it reported invalid rule value.

@waynzh
Copy link
Contributor

waynzh commented Dec 10, 2023

@FloEdelmann @Thomasan1999 @J-Michalek I can give this a try.
I recently met this requirement as well and put up a draft PR.

It differs from the original order property, so I added a new Boolean type property called defineExposeLast. However, there are still some implementation details that I may need some help.

  • open to suggestions for a better option name…
  • Should we include defineExpose within the order schema? There is a potential conflict in the options, like:
    { order: ['defineExpose', 'defineProps'], defineExposeLast: true }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants