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

Proposal for a New ESLint Rule: No Literals in Vue Templates #2516

Open
kaokei opened this issue Aug 1, 2024 · 0 comments
Open

Proposal for a New ESLint Rule: No Literals in Vue Templates #2516

kaokei opened this issue Aug 1, 2024 · 0 comments

Comments

@kaokei
Copy link

kaokei commented Aug 1, 2024

Please describe what the rule should do:

Object literals, array literals, and function literals can cause unnecessary re-renders in Vue components because these literals always generate new objects.

We hope to have a new ESLint rule that can alert us when we unconsciously use literals in Vue templates. It is very convenient and quick to casually write a literal, which can significantly degrade the performance of the component.

For example, in many sample codes of ant-design-vue, object literals are directly used. This is especially true for the table component. When rendering a large amount of data, even if data outside the table is modified, it will still cause the table to re-render.

What category should the rule belong to?

[ ] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[X] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

<div :arr="[]"></div>
<div :arr="[1,2,3]"></div>
<div :obj="{}"></div>
<div :obj="{name:'Tom', age: 123}"></div>
<div :callback="() => someFunction(someArgs)"></div>

Additional context

vuejs/vue#4060

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

1 participant