'Vue/TypeScript/ESLint/Prettier/Vetur formatting doesn't work
Trying to get Vue/TypeScript/ESLint/Prettier/Vetur formatting in VS Code is a nightmare. There are many many GitHub issues and StackOverflow posts on this but I assure you this is not a duplicate. I have followed every tutorial and none of them work. Some of them fix one problem but introduce another. Some of them don't fix any problems. Some of them crash VS Code. Most conflict with each other in the advice they prescribe, including multiple official sources. Many are outdated, referencing obsolete config properties.
I want VS Code to lint and format my .vue and .ts files when I save.
I have spent hours and tried many, many configurations from different posts and tutorials, but this is the closest I have gotten to something that works. With the below configuration, however, whenever saving a .vue file, elements in the .vue files get momentarily wrapped onto a new line, and then immediately reverted back to a single line element:
Below are my current configuration files:
.eslintrc.js
const { resolve } = require('path');
module.exports = {
root: true,
parserOptions: {
extraFileExtensions: ['.vue'],
parser: '@typescript-eslint/parser',
project: resolve(__dirname, './tsconfig.json'),
tsconfigRootDir: __dirname,
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module' // Allows for the use of imports
},
env: {
browser: true
},
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'plugin:vue/recommended'],
plugins: ['@typescript-eslint', 'vue'],
globals: {
ga: true, // Google Analytics
cordova: true,
__statics: true,
process: true,
Capacitor: true,
chrome: true
},
rules: {
'prettier/prettier': ['error', { usePrettierrc: true }],
'prefer-promise-reject-errors': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': ['error', { allow: ['private-constructors'] }],
'vue/no-v-html': 'off',
'vue/no-template-shadow': 'off',
'vue/max-attributes-per-line': 'off',
quotes: ['warn', 'single', { avoidEscape: true }],
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
}
};
.prettierrrc
{
"singleQuote": true,
"semi": true,
"useTabs": false,
"printWidth": 150,
"arrowParens": "avoid",
"trailingComma": "none",
"endOfLine": "auto"
}
settings.json
{
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"vue"
],
"typescript.tsdk": "node_modules/typescript/lib",
"vetur.experimental.templateInterpolationService": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"editor.detectIndentation": false,
"editor.tabSize": 2
}
Does anyone out there actually have this working?
Solution 1:[1]
I've been having some conflict issues between @vue/prettier and eslint. Removing @vue/prettier the problem disappeared. After researching the package I realized that it was a temporary solution until prettier supported Vue natively, and it already does.
I honestly don't know why this package is still recommended by installing vue-cli but I tested putting 'prettier' in place of '@vue/prettier' and it worked
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mithsew |



