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
Indent script and style tags content in *.vue files #3888
Comments
Same with Prettier 1.10.2 --parser vue
--tab-width 4 Input: <style>
body {
color: #fff;
}
</style>
Output: <style>
body {
color: #fff;
}
</style>
Expected behavior: I would prefer the output to stay unchanged.. |
Why would you want an additional level of indentation there? |
For me, I view the contents of a script tag like the contents of any other html tag - I indent its body. So for me, it's consistency. |
same for me.. |
Current behaviour matches the default for |
It's a blocker for using prettier for me and many others. |
@GrahamCampbell would you be able to explain why it is a blocker? |
I think we should follow the most common Vue convention here, if there is one. |
Also there are two different schools for HTML: <html>
<head>
<title>This is more consistent</title>
</head>
<body>
<div></div>
</body>
</html> <html>
<head>
<title>than this</title>
</head>
<body>
<div></div>
</body>
</html> |
Yes, for HTML, but now we’re talking Vue :) Which similar, but not quite the same. |
Just for fun: https://twitter.com/PrettierCode/status/960584198376566784 :) |
Fwiw, when I implemented this, I followed the vue official website example: https://vuejs.org/v2/guide/single-file-components.html |
I was just checking the documentation for the same reason.. and it looks like in the unit test section they are indenting.. https://vuejs.org/v2/guide/unit-testing.html 😕 |
In the style guide there is one example where the content of the <!-- TodoItem.vue -->
<template>
<span>
{{ todo.text }}
<button @click="removeTodo(todo)">
X
</button>
</span>
</template>
<script>
import { mapActions } from 'vuex'
export default {
props: {
todo: {
type: Object,
required: true
}
},
methods: mapActions(['removeTodo'])
}
</script> Same for <template>
<button class="c-Button c-Button--close">X</button>
</template>
<!-- Using the BEM convention -->
<style>
.c-Button {
border: none;
border-radius: 2px;
}
.c-Button--close {
background-color: red;
}
</style> I think this is controverse and a configuration option should be provided. |
We want less options... not more :) |
Here's an actual argument why it's beneficial to have indentation: It allows you to use (indentation-based) code folding to collapse the |
@felixfbecker Is that the case? Folding is available for tags, it is not really dependant on its content. But looks like VSCode check for indentation to make elements foldable. There is an issue open about it microsoft/vscode#3422 |
Yes, it is a good reason. From my comment earlier i just wanted to say it is official. I do not care what is used in the end when it is consistent :) Inlined pictures: |
If you have the Vue plugin installed it folds them correctly.. but not out of the box VS Code |
I'd vote for indentation too. For widest and easiest editor support for folding |
NB Laravel code style indicates indentation: https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Console/Presets/vue-stubs/ExampleComponent.vue. |
For what it's worth from the 241 people that voted in the Twitter poll here are the results..
if we remove the whatever then it becomes
and since whatever would do whatever they should be included with the majority..
|
What? |
He is saying that people who say |
prettier and eslint-plugin-vue conflict for indent rule.they say we should not use it together. |
I think the big split there indicates that configuration is needed. |
This was going to be a Vue only setting, not affecting other html like code. It would have been implemented and released by now. However, Someone thought it might be wiser to add html to the scope and thus introduced a whole new level of complexity and interested parties. And that’s called scope creep. It kills good projects. A better approach would have been to implement the feature as previously agreed for Vue only. Only after that was done, we could create a new issue to consider including html as a new feature. |
This is not how milestones work 😅 |
I've created a PR (#6077) which introduces a new option:
I think we can move the technical discussion over there. |
In #6077 we learned that making a generic option for all HTML-like languages sounded like a good idea, but it still needed Vue-specific behaviors and didn’t work out very well in practice. So after that exploration we decided to go with a simpler Vue-specific option instead: I’m really sorry for all the back-and-forth! |
#6157 has been merged, adding |
@lydell looking for this feature in release / specifically in vscode prettier, is there going to be one soon? |
Most likely by the end of this week :) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@jackkoppa We started the release process for 1.19.0 a while ago, but realized that we need to get a few more PRs in to make a stable release. We’ve been doing a lot of work since then and want to make a release as soon as possible! |
thanks @lydell, really appreciate it! |
Any updates? I know it's just been two weeks, but I desperately need this feature! |
It's coming. |
Yep, release will be in near future, i think we can close this issue /cc @lydell |
Let’s close it once 1.19 is out. Maybe today. |
Keep track of #6787. 👀 |
1.19 is released! 🎉 |
Prettier 1.10.2
Playground link
When I have a Vue.js file:
How do I stop prettier changing the indentation to:
The text was updated successfully, but these errors were encountered: