I am using VScode for Vue development using Prettier and Eslint.
Currently, Prettier is formatting my code like this:
What I'd like is to force the following
If I manually change it to my wanted format it won't mark it as incorrect, but it also doesn't do this format by default.
Is there a way to accomplish this by default?
My relevant VScode Settings.json
"prettier.disableLanguages": ["json"],
"[scss, css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"vetur.validation.template": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true,
"html.format.wrapAttributes": "force-aligned",
"sync.gist": "30b867ce7d7d1360ee7bad0cf5599fc3",
"sync.autoDownload": true,
"sync.autoUpload": true,
"sync.forceUpload": false,
"sync.removeExtensions": false,
"sync.quietSync": true,
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
My .prettierrc settings
{
"trailingComma": "none",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
My eslintrc.js settings
extends: [
'plugin:vue/recommended',
'eslint:recommended',
'prettier/vue',
'plugin:prettier/recommended'
],
plugins: ['vue', 'prettier'],
Set the option in settings. Appending this line to the end of your settings. json file means Prettier will only wrap the line when it exceeds 1000 characters (essentially never). You can change this number to preference, for reference the default is 80 . Just make sure to save changes to the file and you are done!
(Tabs will be used for indentation but Prettier uses spaces to align things, such as in ternaries.)
Try running npx prettier --write . on your project's directory. This command will tell prettier to fix simple errors (such as this one) when found. To prevent this error from happening again you can either set "end-of-line" to auto on your .
Adding this to the .prettierrc or .prettierrc.json file seems to fix this kind of issue:
"htmlWhitespaceSensitivity": "ignore"
Yours would look like this:
{
"trailingComma": "none",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"htmlWhitespaceSensitivity": "ignore"
}
To understand better if this is a good solution for you, you can read about this topic: Whitespace-sensitive formatting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With