Rule Proposal: `vue/component-tags-order`
See original GitHub issuePlease describe what the rule should do:
This rule warns about the order of the script, template & style tags.
What category of rule is this? (place an “X” next to just one item)
[x]
Enforces code style
[ ]
Warns about a potential error
[ ]
Suggests an alternate way of doing something
[ ]
Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
vue/component-tags-order: [“warning”, order: [ “script”, “template”, “style” ] ];
<template></template>
<script></script>
<style></style>
However, the following should be considered fine:
<script></script>
<template></template>
<style></style>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:12 (7 by maintainers)
Top Results From Across the Web
vue/component-tags-order
Rule Details #. This rule warns about the order of the top-level tags, such as <script> , <template> & ...
Read more >Vue.js style guide - GitLab Docs
Properties in a Vue Component: Check order of properties in components rule. :key. When using v-for you need to provide a unique :key...
Read more >@vue/eslint-plugin - npm
All component-related rules are being applied to code that passes any of the following checks: Vue.component() expression; export default {} in ...
Read more >ESLint Vue plugin showing false positives for vue/comment ...
All you need to do is add eslint-disable-next-line vue/component-tags-order this line as comment above anywhere you using comments within ...
Read more >Linting Vue.js Components with eslint-plugin-vue - DigitalOcean
Usage · plugin:vue/base - Just the basic rules to make the parsing work. · plugin:vue/essential - The above, plus rules that exist solely...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’ll have to discuss the best default for this. I think
template
,script
,style
is the most common, because it’s what we usually demonstrate in the docs currently, but I’ve been somewhat recently convinced thatscript
,template
,style
makes more sense, because:script
is probably the least likely tag to be missingscript
defines the interface for the component, which is probably the most referred-to informationscript
when adding new classes to thetemplate
andstyle
I’ll ping some other contributors for their thoughts here.
Unfortunately it’s not possible to implement at this moment @mario-d-s The
vue-eslint-parser
returns an original AST with an extratemplateBody
property that contain AST describing Vue template. But we don’t know anything aboutstyle
tag.Could we perhaps get the following AST @mysticatea?
It would make things easier, and maybe we wouldn’t even need an extra template body visitor (though it’s just my lucky guess).
Alternatively we might add an extra field next to
templateBody
with informations about top-level tags - it would most likely be backwards compatible change. We already have access to the root AST from HTML Parser so it should be pretty straightforward to implement invue-eslint-parser
.Looking once again at
templateBody
got me thinking 🤔Do you remember @mysticatea what was the reason behind assigningresult.ast.templateBody = templateBody
instead of straightresult.ast.templateRoot = rootAST
? Looks like it might just be the solution - it would also allow us to report too many lines between tags and warn about using not scoped styles later on.I’m happy to help and hear your thoughts @mysticatea