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

disallow name in Options API component #2087

Open
privatenumber opened this issue Feb 15, 2023 · 1 comment
Open

disallow name in Options API component #2087

privatenumber opened this issue Feb 15, 2023 · 1 comment

Comments

@privatenumber
Copy link
Contributor

Please describe what the rule should do:

Disallow name from being set on Option API style components.

The name property should generally be the file name, and since vue-loader defaults the component name with the file name, it's not necessary to set manually.

This rule will be helpful in discouraging the practice and removing unused strings in the codebase for a smaller bundle size.

FYI In Vue 3, there's no way to set the component name; it's just the file name.

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>
export default {
  name: 'ComponentName'
})
</script>

However, I think recursive components should be fine (unless vue-loader is able to resolve the self-recursion by file name):

<template>
	<div>
		<component-name />
	</div>
</template>
<script>
export default {
  name: 'ComponentName'
})
</script>

Additional context

Perhaps this rule can be merged with https://eslint.vuejs.org/rules/require-name-property.html

@ota-meshi
Copy link
Member

Thank you for suggesting a new rule.

Perhaps this rule can be merged with https://eslint.vuejs.org/rules/require-name-property.html

I think it makes sense to deprecate the require-name-property rule and add a new rule to optionally disallow/allow the name option.

If you want to disallow the name property early on, you may be able to use the no-restricted-component-options rule. (Note, however, that recursive component uses are not checked.)
https://eslint.vuejs.org/rules/no-restricted-component-options.html

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

No branches or pull requests

2 participants