VS Code 1.92.1
Ubuntu 24.04
Astro based project
Prettier extension installed and set formatter for code-snippets extension as below
.prettierrc file content
<code>printWidth: 140,
semi: true,
singleQuote: false,
tabWidth: 2,
useTabs: false,
plugins: ["prettier-plugin-astro", "prettier-plugin-tailwindcss" /* Must come last */],
overrides: [
{
files: "*.astro",
options: {
parser: "astro",
},
rules: {
quotes: ["error", "double", { avoidEscape: true }],
},
},
],
</code>
<code>printWidth: 140,
semi: true,
singleQuote: false,
tabWidth: 2,
useTabs: false,
plugins: ["prettier-plugin-astro", "prettier-plugin-tailwindcss" /* Must come last */],
overrides: [
{
files: "*.astro",
options: {
parser: "astro",
},
rules: {
quotes: ["error", "double", { avoidEscape: true }],
},
},
],
</code>
printWidth: 140,
semi: true,
singleQuote: false,
tabWidth: 2,
useTabs: false,
plugins: ["prettier-plugin-astro", "prettier-plugin-tailwindcss" /* Must come last */],
overrides: [
{
files: "*.astro",
options: {
parser: "astro",
},
rules: {
quotes: ["error", "double", { avoidEscape: true }],
},
},
],
Note: this is working for Astro and normal file also so please do not suggest that the config is wrong
.editorconfig
<code>root = true
[*]
end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
</code>
<code>root = true
[*]
end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
</code>
root = true
[*]
end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
and below is the snippet file from vs code
log.code-snippets
<code>
{
"blog front matter": {
"scope": "astro, javascript, javascriptreact, typescript, typescriptreact",
"prefix": "bfm",
"body": [
"---",
"ntitle: """,
"ndescription: ",
"npublishDate: ",
"ntags: ["blog"]",
"ndraft: true",
"n---",
],
"description": "Creates an element using document.createDocumentFragment"
}
}
and when save ( `Ctrl + S` ) this file,
it changed `body` content in one line as below
like
``` json
"body": ["---", "ntitle: """, "ndescription: ", "npublishDate: ", "ntags: ["blog"]", "ndraft: true", "n---"],
</code>
<code>
{
"blog front matter": {
"scope": "astro, javascript, javascriptreact, typescript, typescriptreact",
"prefix": "bfm",
"body": [
"---",
"ntitle: """,
"ndescription: ",
"npublishDate: ",
"ntags: ["blog"]",
"ndraft: true",
"n---",
],
"description": "Creates an element using document.createDocumentFragment"
}
}
and when save ( `Ctrl + S` ) this file,
it changed `body` content in one line as below
like
``` json
"body": ["---", "ntitle: """, "ndescription: ", "npublishDate: ", "ntags: ["blog"]", "ndraft: true", "n---"],
</code>
{
"blog front matter": {
"scope": "astro, javascript, javascriptreact, typescript, typescriptreact",
"prefix": "bfm",
"body": [
"---",
"ntitle: """,
"ndescription: ",
"npublishDate: ",
"ntags: ["blog"]",
"ndraft: true",
"n---",
],
"description": "Creates an element using document.createDocumentFragment"
}
}
and when save ( `Ctrl + S` ) this file,
it changed `body` content in one line as below
like
``` json
"body": ["---", "ntitle: """, "ndescription: ", "npublishDate: ", "ntags: ["blog"]", "ndraft: true", "n---"],
How do we prevent to do it, is there any settings in prettier or what?
Note: if I change default formatter to vsode one then it works as desired;
project.code-workspace
<code>"[snippets]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
</code>
<code>"[snippets]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
</code>
"[snippets]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
but what is missing here?