To use this VSCode extension for formatting JavaScript and TypeScript with prettier-eslint, ensure the following packages are installed, locally:
prettier@^3eslint@^8prettier-eslint@^16@typescript-eslint/parser@^6andtypescript@^5(Only for TypeScript projects)
The Prettier extension and the ESLint extension are not required, but having the ESLint extension is recommended to display lint errors while editing.
Install prettier, eslint and prettier-eslint as dev dependencies in your project. Use the appropriate command based on your project requirements. The commands below use pnpm but you can also use npm. Replace pnpm add with npm i if needed.
pnpm add -D prettier@^3 eslint@^8 prettier-eslint@^16pnpm add -D prettier@3 eslint@^8 prettier-eslint@^16 @typescript-eslint/parser@^6 typescript@^5Configure your project by creating or updating a settings.json file at the project's root. If you already have a .vscode/settings.json file, skip the first two steps.
-
Open the command palette in VSCode:
CTRL + SHIFT + P(Windows)CMD + SHIFT + P(Mac OS)
-
Type
Preferences: Open Workspace Settings (JSON). -
In the
.vscode/settings.jsonfile, copy and paste the following settings: -
Restart VS Code
Your project is now set up to automatically format code upon saving.
The extension uses ESLint and Prettier configuration files. These files are resolved from the file being formatted, searching up the file tree.
Refer to ESLint configuration
Use .eslintrc.* or an eslintConfig field in package.json.
Refer to Prettier configuration
prettierfield inpackage.json.prettierrcfile (JSON or YAML).prettierrc.jsor.prettier.config.jsfile.prettierrc.tomlfile
A big shoutout to idahogurl for her fantastic work on vs-code-prettier-eslint, which forms the backbone of this project. Thank you for your dedication to the developer community! 👏🚀
{ "editor.defaultFormatter": "exceptionptr.vscode-prettier-eslint", "editor.formatOnType": false, // required "editor.formatOnPaste": true, // optional "editor.formatOnSave": true, // optional "editor.formatOnSaveMode": "file", // required to format on save "files.autoSave": "onFocusChange", // optional but recommended }