A Visual Studio Code Extension to format JavaScript and TypeScript code using the prettier-eslint package.
Please create an issue before adding a rating. Keep in mind that I work full-time and I am the only contributor currently. I'd LOVE to have more contributors. See the Contributing section below.
This extension requires the following NPM packages to be installed either locally or globally:
prettier@1.9.1eslint@6.8.0@typescript-eslint/parser@^3.0.0andtypescript@^3.9.3(Only for TypeScript projects)vue-eslint-parser@~7.1.0(Only for Vue projects)
Support for Prettier 2 and ESLint 8
- Open Extensions
- Search Prettier ESLint
- For a new installation, click down arrow next to Install button. Choose Install Pre-Release Version
- For existing installation, click Prettier ESLint. In the right screen, click Switch to Pre-Release Version button
These projects are setup to work with the VS Code Prettier ESLint extension. Use them as a boilerplate for your project or as a reference for an existing project. If you don't see an example for your tech stack, create a PR of a working example.
- Check for an error by opening the
Viewmenu and clickOutput - Select
Prettier ESLintfrom the dropdown to the right
- Open a JavaScript (
.jsor.jsx) or TypeScript (.tsor .tsx) file - Press
CTRL + SHIFT + P(Windows/Linux) orCMD + SHIFT + P(macOS) to open the command palette - Start typing
Format Document Withand selectPrettier ESLint - Click on
Outputto open the panel - If you see Error: Cannot find module, quit and restart Visual Studio Code
- If restarting did not work:
- Make sure you have the required packages installed locally (global installations don't work sometimes)
- Repeat Step 8
Notes:
-
The Prettier extension is not required.
-
The ESLint extension is not required. However, it is needed to have lint errors show while editing your file.
-
In your project, install devDependencies
npm install --save-dev eslint@6.8.0 prettier@1.9.1
OR
yarn add -D eslint@6.8.0 prettier@1.9.1
-
For TypeScript projects (
.ts&.tsxfiles) install additional package under devDependenciesnpm install --save-dev @typescript-eslint/parser@^3.0.0
OR
yarn add -D @typescript-eslint/parser@^3.0.0
-
For Vue projects (
.vuefiles) install additional package under devDependenciesnpm install --save-dev vue-eslint-parser@~7.1.0
OR
yarn add -D vue-eslint-parser@~7.1.0
- Install the extension
- Quit VS Code
- Restart VS Code
- Open the file you want to format
- Press
CTRL + SHIFT + P(Windows/Linux) orCMD + SHIFT + P(macOS) to open the command palette - Start typing
Format Document Withand select it - Choose the bottom item
Configure Default Formatter - Choose
Prettier ESLint
Once installed, open a JavaScript (.js or .jsx) or TypeScript (.ts or .tsx) file. Press SHIFT + OPTION + F (macOS) or SHIFT + ALT + F (Windows/Linux) to format a file.
You can enable the Format on Save setting to avoid entering the command all the time.
- Set
Prettier Eslintas the default formatter as detailed above - Open
UserorWorkspacesettings
- On Windows/Linux -
File > Preferences > Settings - On MacOS -
Code > Preferences > Settings
- Start typing
Format onand select it - Check
Format on Save(found mid-page in the right panel) - Ensure both
Format on InputandFormat on Pasteare disabled. They are not supported functionality
Afterward, the file should format automatically once you save it
For the best performance, change Auto Save to onFocusChanged. This will have the editor save changes when you switch to another file or another program. The default setting makes the file save after you stop typing for an interval. This causes the formatter to run frequently thus taking more computer resources.
- Open
UserorWorkspacesettings
- On Windows/Linux -
File > Preferences > Settings - On macOS -
Code > Preferences > Settings
- Start typing
Auto Saveand selectonFocusChanged
The extension uses your ESLint and Prettier configuration files. These files are resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found.
(From https://eslint.org/docs/user-guide/configuring)
Use a JavaScript, JSON or YAML file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an .eslintrc.* file or an eslintConfig field in a package.json file.
(From https://prettier.io/docs/en/configuration.html)
Prettier uses cosmiconfig for configuration file support. This means you can configure prettier via (in order of precedence):
- A
"prettier"key in yourpackage.jsonfile. - A
.prettierrcfile, written in JSON or YAML, with optional extensions:.json/.yaml/.yml(without extension takes precedence). - A
.prettierrc.jsorprettier.config.jsfile that exports an object. - A
.prettierrc.tomlfile, written in TOML (the.tomlextension is required).
If you have suggestions for how this extension could be improved, or want to report a bug, open an issue! I'd love all and any contributions. If you are interested in contributing to the project, check out the Contributing Guide.
Thanks goes to these wonderful people (emoji key):
Rebecca Vest π¬ π» π π π π€ π |
Thomas Bekaert π» |
This project follows the all-contributors specification. Contributions of any kind welcome!


