Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

josephfrazier/prettier_d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

No longer maintained, try https://github.com/mikew/prettier_d_slim instead (context)

prettier_d

Build Status SemVer License

Makes prettier the fastest formatter on the planet.

Table of Contents

"But prettier is pretty fast already, right?"

Yes, it's actually super fast. But the node.js startup time and loading all the required modules slows down formatting times. prettier_d reduces this overhead by running a server in the background. It brings the formatting time down from 0.25 seconds to 0.1 seconds on a 3265 byte file If you want to format from within your editor whenever you save a file, prettier_d is for you.

Install

This will install the prettier_d command globally:

yarn global add https://github.com/josephfrazier/prettier_d
# or
npm install -g https://github.com/josephfrazier/prettier_d

Usage

To start the server and format a file, just run:

prettier_d file.js

On the initial call, the prettier_d server is launched and then the given file is formatted. Subsequent invocations are super fast.

How does this work?

The first time you use prettier_d, a little server is started in the background and bound to a random port. The port number is stored along with a token in the root directory of your repo (or ~/.prettier_d if the repo root can't be found). You can then run prettier_d commands the same way you would use prettier and it will delegate to the background server.

Commands

Control the server like this:

prettier_d <command>

Available commands:

  • start: start the server
  • stop: stop the server
  • status: print out whether the server is currently running
  • restart: restart the server
  • [options] file.js file.js: invoke prettier with the given options. The prettier engine will be created in the current directory. If the server is not yet running, it is started.

prettier_d will select a free port automatically and store the port number along with an access token in the root directory of your repo (or ~/.prettier_d if the repo root can't be found).

Type prettier_d --help to see the supported prettier options.

Editor integration

See https://github.com/prettier/prettier#editor-integration

Real-time formatting in Vim

asciicast

If you use Vim, and you'd like prettier_d to format your code as you type, install Neoformat and add this to your ~/.vimrc:

autocmd FileType javascript setlocal formatprg=prettier_d\ --parser=babel
autocmd BufWritePre,TextChanged,InsertLeave *.js Neoformat

" Use formatprg when available
let g:neoformat_try_formatprg = 1
" https://github.com/sbdchd/neoformat/issues/25
let g:neoformat_only_msg_on_error = 1

Then, make sure you've started the server: prettier_d start.

This will format your code:

  • before each save
  • whenever text is changed in normal mode
  • whenever you leave insert mode

Prettier Banner

Opinionated Code Formatter

JavaScript · TypeScript · Flow · JSX · JSON
CSS · SCSS · Less
HTML · Vue · Angular
GraphQL · Markdown · YAML
Your favorite language?

Azure Pipelines Build Status Codecov Coverage Status Blazing Fast
npm version weekly downloads from npm code style: prettier Chat on Gitter Follow Prettier on Twitter

Intro

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

Input

foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne());

Output

foo(
  reallyLongArg(),
  omgSoManyParameters(),
  IShouldRefactorThis(),
  isThereSeriouslyAnotherOne()
);

Prettier can be run in your editor on-save, in a pre-commit hook, or in CI environments to ensure your codebase has a consistent style without devs ever having to post a nit-picky comment on a code review ever again!


Documentation

Install · Options · CLI · API

Playground


Badge

Show the world you're using Prettiercode style: prettier

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

Contributing

See CONTRIBUTING.md.