Skip to content

✍️ A Sublime Text 3 plugin for Prettier

Notifications You must be signed in to change notification settings

danreeves/sublime-prettier

Repository files navigation

No Maintenance Intended

See alternative: Package Control | Repo


Prettier

This is a Sublime Text 3 plugin for the prettier JavaScript formatter.

Installation

You need prettier installed globally for this plugin to work. See the installation instructions.

npm install -g prettier

Manually

  1. Go to

    • (Mac OS/OS X): ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/"
    • (Windows): C:\Users\[username]\AppData\Roaming\Sublime Text 3\Packages
  2. git clone [email protected]:danreeves/sublime-prettier.git or download the zip and extract to that location.

Usage

Command Palette

Format the entire file:
Prettier: Format this file
Format the current selection(s):
Prettier: Format this selection

Hotkeys

  • Linux: ctrl+alt+p
  • Windows: ctrl+alt+p
  • OS X: ctrl+alt+p

You can add custom key bindings using the commands prettier and prettier_selection.

Configuration

The plugin takes the same settings and the prettier tool. See the prettier repo or this repo. You can configure them in Sublime at Preferences > Package Settings > Prettier.

You can turn on the auto formatting on save by setting autoformat to true.

By default prettier config is searched by prettier --find-config-path, but you can define custom locations to search through configLocations.

For example:

{
  // Turns on/off autoformatting on save
  "autoformat": true,

  // Only attempt to format files with extensions set there
  "extensions": ["js", "jsx"],

  // Fit code within this line limit
  "printWidth": 80,

  // Number of spaces it should use per tab
  "tabWidth": 2,

  // Use the flow parser instead of babylon
  "useFlowParser": false,

  // If true, will use single instead of double quotes
  "singleQuote": false,

  // Controls the printing of trailing commas wherever possible
  "trailingComma": false,

  // Controls the printing of spaces inside array and objects
  "bracketSpacing": true,

  // Try prettier config in the user's home folder and in current opened folder
  "configLocations": ["${home_path}/.prettierrc", "${folder}/.prettierrc"]
}

About

✍️ A Sublime Text 3 plugin for Prettier

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages