If you are using vs code then you can put the below two commands in your vscode user settings(settings.json) file for auto-formatting on save and fixing all the code according to your eslint rules.
You can open user settings by using (Ctrl + Shift + P) and then type User settings.
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
Answer from Dharmik Patel on Stack OverflowIf you are using vs code then you can put the below two commands in your vscode user settings(settings.json) file for auto-formatting on save and fixing all the code according to your eslint rules.
You can open user settings by using (Ctrl + Shift + P) and then type User settings.
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
there is problem in my vscode settings was set "Spaces: 4"
[AskJS] Autoformatting issue with prettier and vscode
VS Code Format on Save Performance
visual studio code - Setting ESlint as formatter in VSCode settings.json - what is the proper way? - Stack Overflow
ESLint can't be used as a formatter until the ESLint server is fully initialized.
Videos
Hello, I am banging my head against a wall.
For long I had no autoformatting enabled in Vscode, when eslint (or prettier - I use the eslint prettier package) complained about some styling formatting I hovered over the error and clicked "Fix all problems" in Vscode.
But then I thought I finally need to setup the fix/format on save thingy… I enabled format on save in vscode settings And added this in my settings json in my project:
"editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll.eslint": true },
And it works!
But it seems I have some conflicting rules or stuff. Because I have something like this: some function => {} and when I hit save it formats to add a whitespace inside the curly braces: some function => { }
And here begins my problem. With the space I get an eslint error to remove the whitespace but when saving it adds it again. I am basically stuck lol
I tried to revert the settings in vscode but it keeps happening and I have no idea where to look for to fix this issue?
I will really appreciate any help or hints.
I've recently started experiencing some massive performance problems in VS Code when formatting on save in my nuxt app with prettier.
My windows 11 pc is beefy enough and shouldn't be struggling but I don't know what to do. I've already reinstalled from scratch and disabled extensions. I rely on format on save to be snappy to feel productive.
So what do you all do? Do you use prettier? Just rely on volar for formatting without prettier? Do you not format on save?
"eslint.format.enable": true basically tells VSCode to use ESlint as a formatter for files that are validated by ESLint and to make sure it always uses your default favourite Prettier formatter, you use "editor.defaultFormatter": "esbenp.prettier-vscode" as there can be multiple formatters installed.
You can put this into .vscode/settings.json:
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll": "never"
},
"eslint.format.enable": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"prettier.enable": false
}
What this config does:
- ESLint is used for formatting (check out stylistic)
- You disable prettier
- The autoformat on save will not remove unreachable code, unlike the codeAction
source.fixall
I've heard ESLint can format but I haven't found a clear answer why it seems prettier is used instead of the ESLint formatter. Whenever I try to look it up most comments neglect to mention that ESLint can also format so it's not obvious why prettier would be needed at all.