-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Format Vue SFC root blocks #8465
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
Conversation
# Conflicts: # src/language-html/printer-html.js
With logs enabled and using D:\Shinigami\Documents\Projects\prettier-vue-pug-test>npx prettier test.vue --plugin-search-dir=.
test.vue[parsers:pug:preprocess]: { text: '\n div.text( color = "primary", disabled )\n' }
[parsers:pug:parse]: { text: '\n div.text( color = "primary", disabled )\n' }
[printers:pug-ast:embed]: {
"stack": [
[
{
"type": "indent",
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 3
}
},
"val": 2
},
{
"type": "tag",
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 6
}
},
"val": "div"
},
{
"type": "class",
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 11
}
},
"val": "text"
},
{
"type": "start-attributes",
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
}
}
},
{
"type": "attribute",
"loc": {
"start": {
"line": 2,
"column": 13
},
"end": {
"line": 2,
"column": 32
}
},
"name": "color",
"val": "\"primary\"",
"mustEscape": true
},
{
"type": "attribute",
"loc": {
"start": {
"line": 2,
"column": 35
},
"end": {
"line": 2,
"column": 43
}
},
"name": "disabled",
"val": true,
"mustEscape": true
},
{
"type": "end-attributes",
"loc": {
"start": {
"line": 2,
"column": 47
},
"end": {
"line": 2,
"column": 48
}
}
},
{
"type": "outdent",
"loc": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 3,
"column": 1
}
}
},
{
"type": "eos",
"loc": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 3,
"column": 1
}
}
}
]
]
}
[printers:pug-ast:print]:
.text(color="primary", disabled)
<template lang="pug">
.text(color="primary", disabled)
</template>
<script>
export default {
name: "Hello",
};
</script>
Thats the first time my plugin receiving something from vue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good.
I have one question, should we respect vue-indent-script-and-style
?
Prettier pr-8465
Playground link
--parser vue
--vue-indent-script-and-style
Input:
<script lang="json">
{
"foo": "bar"
}
</script>
<custom lang="json">
{
"foo": "bar"
}
</custom>
Output:
<script lang="json">
{
"foo": "bar"
}
</script>
<custom lang="json">
{
"foo": "bar"
}
</custom>
I'm not sure about that, There might be another problem(but I'm not sure), plugins will format these blocks, what if this language/plugin indent sensitive? Maybe |
tests_config/run_spec.js
Outdated
@@ -56,8 +56,11 @@ const isTestDirectory = (dirname, name) => | |||
dirname.startsWith(path.join(__dirname, "../tests", name)); | |||
|
|||
global.run_spec = (fixtures, parsers, options) => { | |||
// Can't test plugins on standalone | |||
// Can't test plugins on standalone, a empty test to pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can test them if you pass them as objects, not strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried this before... I forgot. Can't work, maybe because there are function
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Let's keep it this way. I might look at this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about a empty test to pass
? This not work too, snapshots don't match.
I ignored it in jest.config.js
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, about passing the plugin as an object. It should work. If it doesn't, something isn't right.
In any case, it makes sense for HTML or XML-based languages <template>
<div>
<p>some content</p>
</div>
</template> But for non XML based languages like <template lang="pug">
div
p some content
</template> IMO makes no sense for such languages |
src/language-html/printer-html.js
Outdated
|
||
let doc; | ||
try { | ||
doc = textToDoc(getNodeContent(node, options), { parser }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This text pass to parser need discuss too,
<custom lang="pug">
div
</custom>
What we should pass to plugin?
"\n div\n"
(current)" div"
(trim leading and trailing empty lines)" div\n"
(trim trailing empty lines)"div"
(this should not consider)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the exact behavior as currently with the embedded markdown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is?
if same
```pug
div
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems removed one line on each side, means extra blank lines kept. https://github.com/prettier/prettier/blob/master/src/language-markdown/utils.js#L220
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beside the fact that my plugin has a bug
embedded markdown
```pug
div
```
currently formats to (bug)
```pug
| div
```
but should format to
```pug
div
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fisker Please update your @prettier/plugin-pug
to v1.4.4
I fixed the bug
This reverts commit 4ca5990.
|
NO NO NO, YOU LIKE THAT! |
OH MY GOD, IT TOOK ME SO LONG TO UNDERSTAND THIS JOKE XD |
If no objection about @prettier/core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job
Changelog? |
Shared a changelog with #8023 |
I forgot discuss this with you guys, now we have extra <template lang="pug">
.text(color="primary", disabled="true")
</template> First, plugins prints own With builtin embed languages, we use In this case, I think I should remove the @thorn0 @Shinigami92 @sosukesuzuki Thoughts? |
I think this can be managed on my (plugin) side. So when the embed function is called, I could remove it at the end. But why is |
Interesting, I had a quick look, seems prettier/src/language-markdown/embed.js Line 36 in e54d4fc
But, I don't think that's the right way, if a plugin didn't add ```foo
text``` ? |
@fisker It's unlikely there is a good reason for that. Just history I guess. Overall, 3rd party plugins should behave the same way the builtin plugins do, and we need to document these requirements. However, in this case, we need to decide first if we want to change this behavior for the builtin plugins and move the addition of the final new line to the core. I think this change would make sense. |
I'm going to remove this |
@fisker Good |
@thorn0 You might want look into this #8465 (comment) |
To play with it,
--plugin-search-dir
won't need when we fix #8474Fixes #6298
docs/
directory)changelog_unreleased/*/pr-XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨