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

Created on 15 Dec 2016  路  32Comments  路  Source: microsoft/vscode-eslint

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.

Most helpful comment

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

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

All 32 comments

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.

@dbaeumer Any estimated time on this?
Sacrificing autofix when migrating from React to Vue.js is a huge issue for me and my team.

Anyway, great job with the plugin! Thanks for the good work!

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.

Oh, I had not aware of that. Thank you for pointing it out!
I will fix it.

Hmm, actually, I could not reproduce it with eslint --fix command... :thinking:

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 } ]

Thank you so much!

Hmm, actually, I could not reproduce it with eslint --fix command...

OK. Let me have a look then. I take the fixes directly from the reported problem.

@dbaeumer Thank a lot.
Still not working properly, having very similar issue that you encountered.
When I try to autofix my elsint issues, I get incorrect textual changes.

Instead of fixing doublequote issue, my