Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In VS Code, Prettier formats AI-generated code when you save the file. Install the “Prettier – Code formatter” extension and a project-local Prettier package, set Prettier as the default formatter, and enable editor.formatOnSave. The trigger is saving—not accepting an AI suggestion—so inserted code that has not been saved will not necessarily be formatted yet.

Set up Prettier in VS Code

  1. From your project directory, install and pin Prettier as a development dependency:

    npm install prettier -D --save-exact

    The Prettier VS Code extension recommends a local project installation so the project uses a consistent version. See the Prettier installation guide and the Prettier VS Code extension documentation.

  2. In VS Code, open Extensions, search for Prettier – Code formatter, and install the extension published by Prettier.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    #1 Best Overall
    Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
    • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
    • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
    • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
    • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
    • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  3. Create a Prettier configuration file at the repository root, such as .prettierrc, and commit it. This keeps formatting rules with the project so the editor, command line, and other IDEs can use the same settings. Prettier supports several configuration formats; JavaScript and TypeScript configuration exports need to match the project’s module setup. If the project has an .editorconfig, Prettier can translate supported properties from it. See Prettier configuration.

  4. In the project, create or edit .vscode/settings.json and add:

    {
      "editor.defaultFormatter": "esbenp.prettier-vscode",
      "editor.formatOnSave": true
    }

    These workspace settings select the Prettier extension and run formatting when a file is saved. The extension documents format-on-save and language-specific settings in its VS Code documentation.

    Rank #2
    Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
    • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
    • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
    • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
    • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
    • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

When does AI-generated code get formatted?

Prettier does not need to identify code as AI-generated. It responds to the editor’s save event and formats supported files according to the project’s configuration. Accept a suggestion, then save the file; if the suggestion is inserted but the file is not saved, format-on-save has not been triggered.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To format immediately without saving, use VS Code’s Format Document command. If you prefer a save action rather than choosing a default formatter, the extension also documents the source.fixAll.prettier code action on save. It respects editor.defaultFormatter; when combining it with ESLint save actions, configure the sequence deliberately so tools do not compete over formatting. See the extension documentation and format-on-save guidance.

Limit formatting to selected languages or files

Enable format-on-save only for specific languages

If Prettier should format only certain languages, place settings in language-specific blocks in .vscode/settings.json, for example:

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
{
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.formatOnSave": true
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.formatOnSave": true
  }
}

Use the language identifiers for the file types you want to include. The extension documentation describes scoping format-on-save settings by language.

Exclude generated or otherwise sensitive files

Add files and directories that should not be rewritten to .prettierignore. This is useful for generated output and applies to editor formatting as well as whole-project commands such as prettier --write .. For one-off formatting of an ignored file, VS Code’s Format Document (Forced) action bypasses ignore status and the requirePragma requirement. Treat that as an explicit exception rather than a reason to include ignored output by default. See the Prettier ignore documentation and the extension documentation.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep editor and command-line formatting consistent

Use a project configuration file for formatting rules and a project-local, pinned Prettier dependency for the formatter version. VS Code settings are useful for editor behavior, but they apply to the extension; they do not replace project configuration for teammates, other IDEs, or command-line runs.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

The VS Code extension resolves the project-local Prettier installation first when one is available. It can use a global module if configured to do so; otherwise, if neither is available, it uses its bundled Prettier. The extension repository says it bundles Prettier 3.x by default and supports projects using local Prettier 2.x. Pinning the project dependency makes the intended version explicit for contributors and CLI workflows. See the extension documentation.

Use another editor or a file watcher

Prettier recommends running from an editor and installing it locally in each project. Its editor integrations page documents support for VS Code, Emacs, Vim, Helix, Sublime Text, JetBrains IDEs, and Visual Studio. Check the individual integration’s settings for the precise save trigger; behavior is not identical across editors. If an editor does not support Prettier, Prettier suggests using a file watcher. See Prettier editor integrations.

Route Trigger What to configure Consistency consideration
VS Code format-on-save Saving a supported file Prettier extension, default formatter, and editor.formatOnSave Use project configuration and a local pinned dependency for shared rules and version.
Manual editor formatting Running Format Document An editor integration that can invoke Prettier Useful for an unsaved file or a deliberate one-off format; it is not automatic.
Another editor integration Depends on that integration’s settings Install and configure the editor’s Prettier integration Confirm its save behavior rather than assuming it matches VS Code.
File watcher Depends on the watcher configuration Configure a watcher for projects where the editor lacks Prettier support Define which files it watches and how it invokes the project’s formatter.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fix common format-on-save problems

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.