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

prefer-builtin-properties-and-methods #2567

Open
fisker opened this issue Sep 29, 2024 · 2 comments
Open

prefer-builtin-properties-and-methods #2567

fisker opened this issue Sep 29, 2024 · 2 comments

Comments

@fisker
Copy link
Contributor

fisker commented Sep 29, 2024

Please describe what the rule should do:

Prefer use $emit, $slots, etc in <template> instead of variables defined in <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:

<!-- Bad -->
<script setup>
const emit = defineEmits('foo')
</script>
<template>
	<button @click="emit('foo')">Foo</button>
</template>
<!-- Good -->
<script setup>
const emit = defineEmits('foo')
</script>
<template>
	<button @click="$emit('foo')">Foo</button>
</template>
<!-- Bad -->
<script setup>
import { useSlots, useAttrs } from 'vue'

const slots = useSlots()
</script>
<template>
	<div>
		<div v-if="slots.foo"><slot name="foo"></slot></div>
	</div>
</template>
<!-- Good -->
<script setup>
import { useSlots, useAttrs } from 'vue'

const slots = useSlots()
</script>
<template>
	<div>
		<div v-if="$slots.foo"><slot name="foo"></slot></div>
	</div>
</template>

Additional context

It can also apply to other properties and methods

@ota-meshi
Copy link
Member

Thank you for proposing the rule. That rule sounds good to me.
But some users may prefer the opposite style. I think it would be better if it was an option.
What do you think?

@jacekkarczmarczyk
Copy link

Definitely, there should be a possibility to set always or never

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

No branches or pull requests

3 participants