microsoft / vscode-eslint

VSCode extension to integrate eslint into VSCode
MIT License
1.75k stars 335 forks source link

Autofix does not work on .vue files #185

Closed mysticatea closed 7 years ago

mysticatea commented 7 years ago

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.

dbaeumer commented 7 years ago

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.

congrady commented 7 years ago

@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!

dbaeumer commented 7 years ago

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.

mysticatea commented 7 years ago

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

mysticatea commented 7 years ago

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

dbaeumer commented 7 years ago

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 } ]
mysticatea commented 7 years ago

Thank you so much!

dbaeumer commented 7 years ago

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.

congrady commented 7 years ago

@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