Comments (13)
Vue's template parser actually allows self closing components (when using string templates directly). Is there anyway to relax these rules?
from eslint-plugin-vue.
@mysticatea have you thought of building the new parser on top of Vue's parser? I can expose the parse method in vue-template-compiler
and you should be able to pretty easily transform the AST to the format suitable for ESLint. It would also be more accurate and kept up-to-date with Vue core updates.
from eslint-plugin-vue.
Though it may be related to these, we might as well try to design plugin architecture of vue-template-compiler
.
from eslint-plugin-vue.
^ I can think of two ways of doing this:
-
Fork
vue-template-compiler
(or start from scratch) and maintain a parallel parser. This would be easier to implement, but keeping both parsers in sync could be extra maintenance burden. -
Improve the parser directly in Vue itself. The concern here is how much extra code this requires, because the compiler will be included in the full build so size is still a concern. Maybe we can implement it in a way that all the token range information logic is nested inside conditional blocks (similar to
process.env.NODE_ENV
) so that they can be stripped away in the browser oriented build?
from eslint-plugin-vue.
Thank you for this issue.
However, this is working correctly. HTML just ignores self-closing sign.
from eslint-plugin-vue.
I got it.
Could you point the source code which transforms self-closing elements?
from eslint-plugin-vue.
There's no transform, but in https://github.com/vuejs/vue/blob/dev/src/compiler/parser/html-parser.js we just treat self closing tags as if they have a closing tag.
from eslint-plugin-vue.
Thank you.
Hmm.
It seems to be hard that I implement it since I'm using a general HTML parser library. It might be realizable if I transform HTML text by regular expressions before parsing, but it's not safe. I will try to support self-closing after I make new HTML parser.
from eslint-plugin-vue.
@mysticatea I would like to integrate eslint-vue into https://github.com/octref/vetur, a editor tool for Vue.
If we can base eslint-vue and vetur on the same template parser, one additional parsing can be saved in editor! Also, fewer parsing incompatibility will be present.
@yyx990803 Currently vue-template-compiler
will be both too much and too little for tooling. On one hand, generating render function string is unnecessary for tool. On the other, tools will need AST node range and location for traversal.
Let's see how can we improve.
from eslint-plugin-vue.
@yyx990803 It would be best if we use the same parser between Vue.js and eslint-plugin-vue
. However, eslint-plugin-vue
needs more information to lint than Vue.js; locations, tokens of AST nodes, comments, etc... vue-template-compiler
looks to not provide those information.
@HerringtonDarkholme The parser that eslint-plugin-vue@3
is using is vue-eslint-parser, an independent package.
from eslint-plugin-vue.
@mysticatea oh yeah that's right...
In that case, is it possible to build the separate parser on top of Vue's own parser, enhancing it with Node location information? If that's possible, we can even use it to produce source maps for compiled render functions.
from eslint-plugin-vue.
Maybe we can implement it in a way that all the token range information logic is nested inside conditional blocks (similar to process.env.NODE_ENV) so that they can be stripped away in the browser oriented build?
Was about to suggest just that! 😄
from eslint-plugin-vue.
@kazupon Thank you for the information.
After I re-thought this, I got idea to implement self-closing on the current parser, then I made it: #34.
from eslint-plugin-vue.
Related Issues (20)
- Offer suggestions in `vue/order-in-components` when autofix is not available
- enforce usage of 'const' or trigger error when reassigning reactive value
- Eslint disable does not take effect HOT 2
- rule `v-on-handler-style` didn't allow async event listener HOT 1
- Empty class breaks eslint for vue/no-restricted-class
- New Rule: disallow using deprecated `next` argument in `NavigationGuard`
- Conflict: doesn't work if using separate overrides .vue and .ts HOT 2
- Rule Proposal: Maximum number of props
- vue/no-v-text-v-html-on-component: it should not warn if a component implements default slot HOT 9
- require-default-prop for optional props HOT 1
- `vue/multi-word-component-names` also applies to pages directory HOT 2
- disallow importing macros: defineProps etc
- `vue/custom-event-name-casing`: should check and report `update:kebab-case`/`update:camelCase` event names too HOT 1
- HTML indent to extend from ESLint Stylistic HOT 1
- unmet peer eslint@"^6.2.0 || ^7.0.0 || ^8.0.0": found 9.0.0 HOT 3
- how to configure for .vue with <script setup lang="ts" HOT 4
- `getCommentsBefore` empty in Vue SFC with two `script` tags HOT 1
- Support for ESLint 9 HOT 4
- Full example for flat config with object
- Under default configuration, HelloWorld.vue in the vite ts template will be detected as an error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-vue.