Please create an issue before adding a rating. Keep in mind that I work full-time. 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:
typescript@^4.4.4 (Only for TypeScript projects)
vue-eslint-parser@^8.0.0 (Only for Vue projects)
Note: For earlier versions of Prettier and/or ESLint, see Support for Earlier Versions section
Download the extension if you haven't already.
First we need to install
eslint as dev dependencies in your project. Run one of the following commands based on your project requirements. The commands listed below use
yarn but you can also use
npm. Just replace
yarn add with
yarn add -D prettier@^2.5.1 eslint@^8.7.0
yarn add -D prettier@^2.5.1 eslint@^8.7.0 @typescript-eslint/parser@^5.0.1 typescript@^4.4.4
yarn add -D prettier@^2.5.1 eslint@^8.7.0 vue-eslint-parser@^8.0.0
Next we need to configure your project to use the extension. To do that, we're going to open or create a
settings.json file at the root of your project. If you already have a
.vscode/settings.json file in your project, you can skip the first two steps below and jump straight to step 3.
- Open the command palette in VS Code by typing:
CMD + SHIFT + P (Mac OS)
CTRL + SHIFT + P (Windows)
In the command palette type
Preferences: Open Workspace Settings (JSON).
.vscode/settings.json file we just opened, copy and paste the following settings
"editor.formatOnPaste": false, // required
"editor.formatOnType": false, // required
"editor.formatOnSave": true, // optional
"editor.formatOnSaveMode": "file", // required to format on save
"files.autoSave": "onFocusChange" // optional but recommended
Restart VS Code
With settings listed above, your project should now be setup to automatically format your code when you save. If you run into any problems, check the troubleshooting guide below.
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.
ESLint Configuration File
.eslintrc.* file or an
eslintConfig field in a
package.json file, both of which ESLint will look for and read automatically.
Prettier Configuration File
Prettier uses cosmiconfig for configuration file support. This means you can configure prettier via (in order of precedence):
"prettier" key in your
.prettierrc file, written in JSON or YAML, with optional extensions:
.json/.yaml/.yml (without extension takes precedence).
prettier.config.js file that exports an object.
.prettierrc.toml file, written in TOML (the
.toml extension is required).
These projects are setup to work with the VS Code Prettier ESLint extension. Use them to help troubleshoot or as a boilerplate for your 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
View menu and click
Prettier ESLint from the dropdown to the right
.jsx) or TypeScript (
.ts or .
CTRL + SHIFT + P (Windows/Linux) or
CMD + SHIFT + P (macOS) to open the command palette
- Start typing
Format Document With and select
- Click on
Output to open the panel
- If you see Error: Cannot find module, quit and restart Visual Studio Code
- If restarting did not work:
- If you saw Error: Cannot find module '@typescript-eslint/parser', view the TypeScript project for a working example.
- Make sure you have the required packages installed locally (global installations don't work sometimes)
Most issues are caused by using an unsupported ESLint version or an invalid ESLint configuration.
You can run
npx eslint --print-config .eslintrc.js to check your ESLint configuration. This prints out the configuration being used after it applies plugins & extended configurations.
Running your files through the Prettier ESLint CLI first is a good way to determine if it's the extension, the
prettier-eslint package, or your configuration.
There are known performance issues with quad-core or slower processors. The slowness comes from the
prettier-eslint package the extension uses.
Support for Earlier Versions
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.
Current Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!