A Visual Studio Extension to format JavaScript code using the prettier-eslint package.
Like prettier-eslint
, this plugin requires both prettier
and eslint
packages to be installed either locally or globally.
Like prettier-eslint
, this plugin requires both prettier
and eslint
packages to be installed either locally or globally.
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.json
file. - A
.prettierrc
file, written in JSON or YAML, with optional extensions:.json/.yaml/.yml
(without extension takes precedence). - A
.prettierrc.js
orprettier.config.js
file that exports an object. - A
.prettierrc.toml
file, written in TOML (the.toml
extension is required).
Once installed, open a JavaScript file. Press CTRL + CMD + P
(macOS) or CTRL + Shift + P
(Windows/Linux) to format a file or a selection of code.
You can enable the Format on Save
setting to avoid entering the command all the time.
- 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 With
and select it - Choose the bottom item
Configure Default Formatter
- Choose
Prettier ESLint
- Set
Prettier Eslint
as the default formatter as detailed above - Open User or Workspace settings
- On Windows/Linux - File > Preferences > Settings
- On macOS - Code > Preferences > Settings
- Start typing
Format on
and select it - Check
Format on Save
(found mid-page in the right panel) - Ensure both
Format on Input
andFormat on Paste
are disabled. They are not supported functionality - Afterward, the file should format automatically once you save it