ESLint and Prettier Format on Save? #13602
Replies: 8 comments 16 replies
|
Hmm I think I finally got it with the help of Claude. Here is what seems to be working for me. If anyone has feedback on my config overall let me know. I'm still pretty new to Zed. {
"assistant": {
"version": "1",
"provider": {
"name": "openai",
"default_model": "gpt-4o"
}
},
"telemetry": {
"metrics": true
},
"features": {
"inline_completion_provider": "supermaven"
},
"language_servers": ["vtsls", "typescript-language-server", "eslint"],
"language_server_options": {
"vtsls": {
"language_ids": [
"typescript",
"javascript",
"typescriptreact",
"javascriptreact"
]
},
"typescript-language-server": {
"language_ids": [
"typescript",
"javascript",
"typescriptreact",
"javascriptreact"
],
"initialization_options": {
"preferences": {
"includeInlayParameterNameHints": "all",
"includeInlayParameterNameHintsWhenArgumentMatchesName": true,
"includeInlayFunctionParameterTypeHints": true,
"includeInlayVariableTypeHints": true,
"includeInlayVariableTypeHintsWhenTypeMatchesName": false,
"includeInlayPropertyDeclarationTypeHints": true,
"includeInlayFunctionLikeReturnTypeHints": true,
"includeInlayEnumMemberValueHints": true
}
}
},
"eslint": {
"language_ids": [
"typescript",
"javascript",
"typescriptreact",
"javascriptreact"
],
"initialization_options": {
"run_formatter": true
}
}
},
"languages": {
"TypeScript": {
"formatter": "prettier",
"code_actions_on_format": {
"source.fixAll.eslint": true
},
"format_on_save": {
"external": {
"command": "prettier",
"arguments": ["--stdin-filepath", "{buffer_path}"]
}
}
},
"TSX": {
"formatter": "prettier",
"code_actions_on_format": {
"source.fixAll.eslint": true
},
"format_on_save": "on"
},
"JavaScript": {
"formatter": "prettier",
"code_actions_on_format": {
"source.fixAll.eslint": true
},
"format_on_save": "on"
}
},
"formatter": {
"code_actions": {
"source.fixAll.eslint": true
}
},
"relative_line_numbers": true,
"theme": "Atelier Forest Light",
"buffer_font_size": 15,
"buffer_font_family": "FuraCode NF",
"vim_mode": true,
"format_on_save": "on",
"autosave": {
"after_delay": {
"milliseconds": 1000
}
},
"indent_guides": {
"render": true,
"character": "│",
"skip_first_level": false
},
"project_panel": {
"file_icons": true
},
"vim": {
"use_multiline_registers": true,
"surround": true,
"sneak": true
}
} |
|
The docs explain how to enable both prettier and eslint, with the following caveat
If anyone is trying to figure out how to get eslint to run after Prettier, the following worked for me "languages": {
"JavaScript": {
"formatter": [
"prettier",
{
"code_actions": {
"source.fixAll.eslint": true
}
}
]
}
} |
|
Although it’s slightly slow, this setup successfully runs both Prettier and ESLint --fix on save for me! "languages": {
"JavaScript": {
"formatter": {
"external": {
"command": "pnpm",
"arguments": ["exec", "prettier", "--stdin-filepath", "{buffer_path}"]
}
},
"code_actions_on_format": {
"source.fixAll.eslint": true
},
"format_on_save": "on"
},
"TypeScript": {
"formatter": {
"external": {
"command": "pnpm",
"arguments": ["exec", "prettier", "--stdin-filepath", "{buffer_path}"]
}
},
"code_actions_on_format": {
"source.fixAll.eslint": true
},
"format_on_save": "on"
},
"TSX": {
"formatter": {
"external": {
"command": "pnpm",
"arguments": ["exec", "prettier", "--stdin-filepath", "{buffer_path}"]
}
},
"code_actions_on_format": {
"source.fixAll.eslint": true
},
"format_on_save": "on"
},
} |
|
I have tried all the different settings in this discussion and none of them made the eslint autofix work when saving. I can't get this dummy code to autofix when saving my file: let hello = 123; // eslint: 'hello' is never reassigned. Use 'const' instead.
console.log(hello);If If run But I'd like that to happen when saving the file... I have installed |
|
Looking at the doc we can set up multiple formatters by providing an array. This seem do properly run eslint and prettier. I've put it top level, but it also work when specified on specific languages |
|
Hmm, I am actually doing something different. I let Zed's auto do it's work last. You can replace the |
|
None of the answers are working for me. Only if I disable all LSP's and manually enable a few via config, only then it works. Talking specifically for Vue SFC files. |
|
Thanks for reaching out. We want to better support our community, and the best way for us to do that is through our official Discord. The team is active there and happy to help. We’re closing the “Help and General Q&A” category on GitHub Discussions and directing all support questions to Discord going forward. |

Uh oh!
There was an error while loading. Please reload this page.
Hi all I'm loving Zed and trying to switch from VSCode. I'm almost there except for this seemingly trivial tweak. I have some eslint formatting rules like sorting Typescript Imports as well as prettier rules. I want Zed to format both of these every time I hit save. For the life of me I can't seem to get them both working. Any ideas how I fix this?
Here is my config
{ "assistant": { "version": "1", "provider": { "name": "openai", "default_model": "gpt-4o" } }, "telemetry": { "metrics": true }, "features": { "inline_completion_provider": "supermaven" }, "language_servers": ["vtsls", "typescript-language-server", "eslint"], "language_server_options": { "vtsls": { "language_ids": [ "typescript", "javascript", "typescriptreact", "javascriptreact" ] }, "typescript-language-server": { "language_ids": [ "typescript", "javascript", "typescriptreact", "javascriptreact" ], "initialization_options": { "preferences": { "includeInlayParameterNameHints": "all", "includeInlayParameterNameHintsWhenArgumentMatchesName": true, "includeInlayFunctionParameterTypeHints": true, "includeInlayVariableTypeHints": true, "includeInlayVariableTypeHintsWhenTypeMatchesName": false, "includeInlayPropertyDeclarationTypeHints": true, "includeInlayFunctionLikeReturnTypeHints": true, "includeInlayEnumMemberValueHints": true } } }, "eslint": { "language_ids": [ "typescript", "javascript", "typescriptreact", "javascriptreact" ], "initialization_options": { "run_formatter": true } } }, "languages": { "TypeScript": { "formatter": "prettier", "code_actions_on_format": { "source.fixAll.eslint": true }, "format_on_save": "on" }, "TSX": { "formatter": "prettier", "code_actions_on_format": { "source.fixAll.eslint": true }, "format_on_save": "on" }, "JavaScript": { "formatter": "prettier", "code_actions_on_format": { "source.fixAll.eslint": true }, "format_on_save": "on" } }, "formatter": { "code_actions": { "source.fixAll.eslint": true } }, "relative_line_numbers": true, "theme": "Atelier Forest Light", "buffer_font_size": 15, "buffer_font_family": "FuraCode NF", "vim_mode": true, "format_on_save": "on", "autosave": { "after_delay": { "milliseconds": 1000 } }, "indent_guides": { "render": true, "character": "│", "skip_first_level": false }, "project_panel": { "file_icons": true }, "vim": { "use_multiline_registers": true, "surround": true, "sneak": true } }All reactions