See alternative: Package Control | Repo
This is a Sublime Text 3 plugin for the prettier JavaScript formatter.
You need prettier
installed globally for this plugin to work. See the installation instructions.
npm install -g prettier
-
Go to
- (Mac OS/OS X):
~/Library/Application\ Support/Sublime\ Text\ 3/Packages/"
- (Windows):
C:\Users\[username]\AppData\Roaming\Sublime Text 3\Packages
- (Mac OS/OS X):
-
git clone [email protected]:danreeves/sublime-prettier.git
or download the zip and extract to that location.
- Format the entire file:
Prettier: Format this file
- Format the current selection(s):
Prettier: Format this selection
- 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
.
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"]
}