Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to apply autofix from ESLint?

Tags:

People also ask

How do you use ESLint autofix?

You can set up ESLint to run auto-fix every time you press CTRL+S (or COMMAND+S ). For ESLint to work correctly on file same, you must change the Visual Studio Code preferences. Go to File > Preferences > Settings (or Code > Preferences > Settings).

How do I get ESLint autofix?

For VS Code, install the ESLint package. Then, to format on save, go to global settings and search for ESLint and turn on the ESLint: Auto Fix On Save option.

What is ESLint fix fix?

eslint --fix will fix every rule violation it is capable of fixing, actually overwrite the code, and print out any warnings or errors it was incapable of fixing. Most errors are not actually automatically fixable.

What are ESLint errors?

ESLint can call out logic errors, such as update code in a for loop that iterates in the wrong direction. It can also call your attention to unused code, such as empty block statements which can indicate something like an incomplete refactoring process.


I'd like to format several files but I'm worried about breaking code.

When I'm saying if it is safe for not, I'm saying that the execution of the code before and after is exactly the same.

For instance, there are rules that look pretty safe to be applied (like indenting). I suppose that changing the number of spaces won't affect the execution of the code.

Then, there are rules that don't look so safe. For instance, changing var to let or const could cause a different execution as var is not exactly the same as let.

So, I'm wondering if there are any auto-fix rule from ESLint that can change the code so the execution is different when applied the --fix thing.