RobinMalfait / prettier-eslint-code

[DEPRECATED] A vscode extension to format javascript using prettier-eslint
24 stars 7 forks source link

don't add custom 'formatOnSave'-logic #1

Closed jrieken closed 7 years ago

jrieken commented 7 years ago

The custom formatOnSave is dangerous because it runs after a file has been saved and triggers another save. That can cause save-loops. For your format-on-save use-case everything is already built in to VS Code. If a user sets the formatOnSave-settings to true we will automatically call the formatters. Because you properly register as such it should just work for you.

Don't hesitate to reach out to me for more info. Also there is a blog post about this: https://code.visualstudio.com/blogs/2016/11/15/formatters-best-practices

RobinMalfait commented 7 years ago

Oh cool, I didn't know about this functionality. But I added checks to see if there is a difference between old and new values.

I indeed add:

So if I understand it correctly I can refactor and delete the formatOnSave method, and use the formatOnSave setting right?

jrieken commented 7 years ago

formatOnSave method, and use the formatOnSave setting right?

Yeah, that's correct and vey much appreciated. The problem with changing and saving a file after it got saved is that another extension might do the same. So even if you have a check the other extension might make chances you didn't expect and vice versa...

The deal is that format on save calls the registered formatting provider, it basically does the same as if the user selects 'Format Document' from the context menu.

RobinMalfait commented 7 years ago

Thank you for clarification, I will fix that in my next release ;)

It's also my first extension, so it is all very new to me