question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vetur Ignores .eslintrc settings when formatOnSave is true

See original GitHub issue
  • [ x ] I have searched through existing issues
  • [ x ] I have read through docs
  • [ x ] I have read FAQ

Info

  • Platform: Linux (Ubuntu 16.04)
  • Vetur version: 0.11.7
  • VS Code version: 1.22.2
  • ESLint extension version: 1.4.8

Problem

When "editor.formatOnSave" is set to true in the VS Code settings, Vetur does not respect the settings in .eslintrc.

Reproducible Case

  1. Install Vetur VS Code Extension
  2. Install ESLint VS Code Extension
  3. Add the following to VS Code User Settings:
  "editor.formatOnSave": true,
  "eslint.validate": [
      "javascript",
      "javascriptreact",
      "vue"
  ],
  "eslint.autoFixOnSave": true,
}
  1. Reload VS Code
  2. Use the vue 3.0 cli (I used version 3.0.0-beta.6) to create a new project: vue create new-project
  3. Choose Manually select features
  4. Choose Linter / Formatter
  5. Choose ESLint + Airbnb config
  6. Choose Lint on save
  7. Choose In dedicated config files
  8. Open the new project in VS Code
  9. Make a change to the App.vue file
  10. *Notice that it changed single quotes to double and removed trailing commas contrary to the .eslintrc config

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:17
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

34reactions
jeffhubecommented, Jan 8, 2019

I solved this by adding the following to the default value for vetur.format.defaultFormatterOptions

"prettier": {
    "singleQuote": true,
    "trailingComma": "all"
}

So it looks like this:

"vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
        "wrap_attributes": "force-expand-multiline",
    },
    "prettyhtml": {
        "printWidth": 100,
        "singleQuote": false,
        "wrapAttributes": false,
        "sortAttributes": false
    },
    "prettier": {
        "singleQuote": true,
        "trailingComma": "all"
    }
}
33reactions
jmcoopercommented, Apr 14, 2018

Looks like I found a config to get this working. If I add the below configuration to VS Code it works although it seems a little glitchy. For example, if in addition to the config below, I also set "editor.formatOnSave": true, then I see the code flash with double quotes and then get correctly formatted with single quotes, so it seems like Vetur might be formatting it with quotes and then ESLint is fixing it afterwards. It would be good if whatever Vetur is doing would respect the .eslintrc config.

Here’s the VSCode config that makes it work:

{
    "eslint.validate": [
        {
            "language": "vue",
            "autoFix": true
        },
        {
            "language": "javascript",
            "autoFix": true
        },
    ],
    "eslint.autoFixOnSave": true,
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint in VSCode not fixing on save - Stack Overflow
Making all our formatter settings look like this: "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll" ...
Read more >
ESLint and Prettier with Vite and Vue.js 3 - Vue School Blog
We just need to install the eslint-config-prettier config. This disables the formatting rules in ESLint that Prettier is going to be responsible ...
Read more >
How to setup ESLint and Prettier with VS Code and VueJS
You can set Vetur as the default by selecting ”Configure Default Formatter” after ”Format Document With…” then select ”Vetur” from the options.
Read more >
Eslint for Vue projects in VSCode - DEV Community ‍ ‍
I'd like to share my VSCode and ESLint configuration that I use in ... fixAll.eslint": true }, "vetur.validation.template": false, "editor.
Read more >
Vetur/Eslint/VS Code - can't set space between parenthesis for ...
Then we should add following to settings.json in VS Code. "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll": true },.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found