I am trying to set up my VSCode editor to autoformat my Vuejs code. I am using the Vetur extension, the Prettier extension, and the ESLint extension.
The problem is that when I save my .vue
files, the single quotes are automatically changed to double quotes in my <template>
elements:
When I write code like so and then save...
<template>
<section>
<section v-if='errored'>
...snip...
</template>
VSCode automatically changes the single quotes to double quotes in the .vue template
section like so:
<template>
<section>
<section v-if="errored"> <--------
...snip...
</template>
And then I get warnings and errors for the rest of the <template>
code. However, the code in the <script>
and <style>
sections of the .vue
single file components are left intact/and/or fixed correctly....it's just the <template>
section that has the above issue. So, do I have my settings correct?
My settings are:
I set my Prettier config file in project root .prettierrc.js
like so:
module.exports = {
singleQuote: true
};
My .eslintrc.js
looks like so:
module.exports = {
root: true,
env: {
node: true
},
extends: [
'plugin:vue/essential',
'plugin:prettier/recommended',
'@vue/prettier'
],
rules: {
'no-console': 'off',
'no-debugger': 'off'
},
parserOptions: {
parser: 'babel-eslint'
}
};
And then in my VSCode user settings I have:
...snip..
"vetur.validation.template": false, <-- turn off Vetur’s linting feature and rely on ESLint + Prettier, instead
"eslint.validate": [
{
"language": "vue",
"autoFix": true
},
{
"language": "html",
"autoFix": true
},
{
"language": "javascript",
"autoFix": true
}
],
"eslint.autoFixOnSave": true,
"editor.formatOnSave": true
And the app's package.json
file contains the following devDependencies:
"devDependencies": {
"@vue/cli-plugin-babel": "^3.2.0",
"@vue/cli-plugin-eslint": "^3.2.1",
"@vue/cli-service": "^3.2.0",
"@vue/eslint-config-prettier": "^4.0.1",
"node-sass": "^4.9.4",
"sass-loader": "^7.1.0",
"vue-template-compiler": "^2.5.17"
}