Giter Club home page Giter Club logo

vs-code-prettier-eslint's Introduction

All Contributors

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.

Prerequisites

This extension requires the following packages to be installed either locally or globally:

Example Projects

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.

Troubleshooting

  1. Check for an error by opening the View menu and click Output
  2. Select Prettier ESLint from the dropdown to the right

troubleshooting

  1. Open a JavaScript (.js or .jsx) or TypeScript (.ts or .tsx) file
  2. Press CTRL + SHIFT + P (Windows/Linux) or CMD + SHIFT + P (macOS) to open the command palette
  3. Start typing Format Document With and select Prettier ESLint
  4. Click on Output to open the panel
  5. If you see Error: Cannot find module, quit and restart Visual Studio Code
  6. If restarting did not work:
    • Make sure you have the required packages installed locally (global installations don't work sometimes)
    • Repeat Step 8

Installation

Notes:

Install Dependencies

  1. In your project, install [email protected], [email protected], & prettier-eslint:^10.1.0 as devDependencies
  2. Additionally install:
    • @typescript-eslint/parser@^3.0.0 for TypeScript projects (.ts & .tsx files)
    • vue-eslint-parser@~7.1.0 for Vue projects (.vue files)

Install the Extension

  1. Install the extension
  2. Quit VS Code
  3. Restart VS Code

Set as Default Formatter

  1. Open the file you want to format
  2. Press CTRL + SHIFT + P (Windows/Linux) or CMD + SHIFT + P (macOS) to open the command palette
  3. Start typing Format Document With and select it
  4. Choose the bottom item Configure Default Formatter
  5. Choose Prettier ESLint

Run the Formatter

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.

Setup Format on Save

  1. Set Prettier Eslint as the default formatter as detailed above
  2. Open User or Workspace settings
  • On Windows/Linux - File > Preferences > Settings
  • On MacOS - Code > Preferences > Settings
  1. Start typing Format on and select it
  2. Check Format on Save (found mid-page in the right panel)
  3. Ensure both Format on Input and Format on Paste are 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.

  1. Open User or Workspace settings
  • On Windows/Linux - File > Preferences > Settings
  • On macOS - Code > Preferences > Settings
  1. Start typing Auto Save and select onFocusChanged

Configuration

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

(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.

Prettier Configuration 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 your package.json file.
  • A .prettierrc file, written in JSON or YAML, with optional extensions: .json/.yaml/.yml (without extension takes precedence).
  • A .prettierrc.js or prettier.config.js file that exports an object.
  • A .prettierrc.toml file, written in TOML (the .toml extension is required).

Contributing

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):


Rebecca Vest

๐Ÿ’ฌ ๐Ÿ’ป ๐Ÿ“– ๐Ÿš‡ ๐Ÿ› ๐Ÿค” ๐Ÿ‘€ โš ๏ธ

This project follows the all-contributors specification. Contributions of any kind welcome!

vs-code-prettier-eslint's People

Contributors

aewing avatar idahogurl avatar profcase avatar quentez avatar rlnt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.