-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
prettier for Vue #491
Comments
Sounds good! Yeah would be happy to help if I can. This all seems feasible, although it would require a new set of reshape plugins to accomplish. Have you had a chance to check out how reshape plugins are built? Probably starting with a |
@jescalan I'm already modifying some plugins :D |
@octref Absolutely, I would love that in fact. |
Hi @octref WDYT about https://github.com/StarpTech/prettyhtml it's already capable of parsing Vue templates (including self-closing elements). |
@StarpTech Thanks a lot for suggesting prettyhtml! I currently don't have much time to work on it myself so it would be great to integrate your work into Vetur. However, for a good Vue-html formatter, I think Here are a few feedback / issues:
<!--[if lte IE 9]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
<![endif]--> The comment regions start/end identifiers need to have the same indentation. You either apply no transformation to all of them or apply a unified indent/outdent to all its children.
<a @click="open = !open">
{{
open
? '[-]'
: '[+] ' + pluralize(comment.kids.length) + ' collapsed'
}}
</a>
<div
attr="foo"
attr="foo"
attr="foo"
attr="foo"
>bar</div> over <div
attr="foo"
attr="foo"
attr="foo"
attr="foo">bar</div> (which is less readable IMO) Question 1: I don't know much about Angular, but which parts are you parsing as interpolations in Vue? For example, in the playground above, it doesn't seem to identify
Question 2: Do you ever foresee yourself implement these Vue style guide points, or should I fork prettyhtml if I want to implement them?
Thanks again for chiming in. This already looks great! |
Hi @octref thanks for the great feedback! I'm free for any change as long as it is reasonable. Just open an issue in prettyhtml and we can work together on a great solution.
I hope I understand your question correctly. Any expression of
The first and the last are already covered but the other rules require an application context because I don't know which tag can be used as self-closing tag. IMHO this should be handled by a Vue linter. I think at first we should focus on a good basic rule set and shouldn't fork it at an early stage. |
Prettyhtml/prettyhtml#19 I agree 👍 |
@StarpTech Sounds good, for Q1, I meant that in this snippet:
What's inside the |
@octref ok I understand but what's your input and expectation? In my opinion attribute values should remain unaffected. In the current state Prettyhtml handle it as space sensitive content but I'm open for different plugins for vue or angular in order to format such things. |
@octref Please consider prettyhtml at first as a general formatter. In the second step, when the base is solid and well thought out we can handle framework specific things. |
@StarpTech I would expect, in prettyhtml's current form, to have: <!-- input -->
<router-link
:to="'/user/' + comment.by + foo + bar + foo + bar + foo + foo + bar + foo + bar">{{ comment.by }}</router-link>
{{ comment.time | timeAgo }} ago
<!-- output -->
<router-link
:to="'/user/' + comment.by + foo + bar + foo + bar + foo + foo + bar + foo + bar"
>{{ comment.by }}</router-link>
{{ comment.time | timeAgo }} ago There are cases like this, which we can deal with later. <template>
<div class="progress" :style="{
'width': percent+'%',
'height': height,
'background-color': canSuccess? color : failedColor,
'opacity': show ? 1 : 0
}"></div>
</template>
I agree. Kudos to your work! I'd suggest setting up Travis/Codecov/Contributing.md soon. There are many people who would like to contribute: #561. If I do get time I can help a bit too :) |
@octref the first case of your last example is already covered |
Looking good. I'll take a look this weekend to integrate prettyhtml. |
@octref any feedback? |
@StarpTech Sorry, had been busy with work. I'm looking at it right now. |
@StarpTech now THATS a killer feature !!! |
Can't wait for this! |
@numfin @alexbudure you can already test the formatter on your codebase to provide me feedback. You can also do it online https://repl.it/@StarpTech/PrettyHtml |
@StarpTech Tried it out and it works great so far. Solves a lot of issues I've been having. How can I integrate this with Vetur? |
@alexbudure that's a question for @octref. |
@octref Any timeline on this? Even a quick integration where you can choose the PrettyHtml instead of JSBeautify would be greatly appreciated! |
YEEEEEAHBOOOOYYYYYYYYYYYYYYYYYYYYYIIIIIIIIIIII |
There is an active PR that adds HTML/Vue support to prettier. It might not be necessary thanks to prettyhtml, but worth a look. |
@nklayman that's right and I'm aware of that from the beginning. I hadn't time to investigate full-time on it and in our company we looked for a fast and maintainable solution. Before I will repeat myself: https://github.com/Prettyhtml/prettyhtml#why |
Is there a reason why Vetur is defaulting to a new library instead of contributing to https://github.com/beautify-web/js-beautify? They've finally found contributors. |
Prettyhtml integration is working brilliantly for me, thank you to @StarpTech and @octref for implementing! |
|
@octref @StarpTech, Please check my issue the details. |
We already have the infra for splitting Vue component into multiple regions, and currently we feed
<template>
: none<style>
: prettier with parsercss
/scss
/less
<script>
: prettier with parserbabylon
/typescript
Instead of waiting for prettier's html formatter, https://github.com/reshape/reshape by @jescalan seems to be in better shape already. With two more things, I think I can put it in as the default html formatter for Vetur:
printWidth
. This is especially important for wrapping html attributes. eg:to
Handling of interpolation in attributes and mustache brackets. Example from Vue doc: https://vuejs.org/v2/guide/class-and-style.html#Object-Syntax
The class object can be very long and needs to be formatted to multiline.
Another thing we could do is to make a CLI based on prettier + reshape + vue-template-compiler. Basically just using
vue-template-compiler
instead of Vetur's region splitting.@jescalan Do you have any thoughts? Would you be interested in working together on this?
The text was updated successfully, but these errors were encountered: