vscode-eslint: Autofix does not work on .vue files

I’m using ESLint with vue-eslint-parser then I enabled vscode-eslint for .vue files. vue-eslint-parser supports autofix for .vue files. But eslint.autoFixOnSave option and eslint.executeAutofix command did not work on .vue files.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 32 (23 by maintainers)

Most upvoted comments

I only add this to settings.json and it works :

"eslint.validate": [
        { "language": "vue", "autoFix": true },
        { "language": "html", "autoFix": true }
    ]

I published version 1.2.2 of the ESLint extension. It allows for selective autoFix configuration. From the readme:

Added configuration options to enable code actions and auto fix on save selectively per language. In release 1.2.1 code actions and auto fix on save very still only available for JavaScript. In 1.2.2 you can now enable this selectively per language. For compatibility it is enabled by default for JavaScript and disabled by default for all other languages. The reason is that I encounter cases for non JavaScript file types where the computed fixes had wrong positions resulting in ‘broken’ documents. To enable it simply provide an object literal in the validate setting with the properties language and autoFix instead of a simple string. An example is:

"eslint.validate": [ "javascript", "javascriptreact", { "language": "html", "autoFix": true } ]

I am working on making this a configuration. However as long as the plugins are not fixing this I can’t do much. The vue-eslint-parser is showing the same problem. That auto fix positions are of therefore applying them results in incorrect textual changes:

cast

@mysticatea are you aware of this. I tested this with the vue-eslint-parser plugin.

This is because of https://github.com/BenoitZugmeyer/eslint-plugin-html/issues/38. I took a defensive approach here to ensure that this doesn’t break code especially when enable during save. I will update the readme to make this more clear.

I am still debating whether I should provide different options for different file types.