- Installation guide
- Using in the command line with node.js
- Supported languages / plugins
- Additional plugins
- Provide Default Configuration
- Local Instance
- Editor integration
Wanna run prettier in your editor, but fast? Welcome to prettierd!
This is built on top of core_d.js and integrates with prettier.
$ npm install -g @fsouza/prettierd
NOTE: npm
comes builtin to node
.
Alternatively, users may also use homebrew:
$ brew install fsouza/prettierd/prettierd
The prettierd script always takes the file in the standard input and the positional parameter with the name of the file:
$ cat file.ts | prettierd file.ts
Many parsers ship with prettierd, including JavaScript, TypeScript, GraphQL, CSS, HTML and YAML. Please notice that starting with version 0.12.0, prettierd now supports invoking the local version of prettier, so instead of adding new languages to prettierd, you should rely on that feature to use it locally with your custom version of prettier and enabled plugins.
Additional plugins can be supported by installing them and adding them to the
prettier configuration. For example, to use the Ruby plugin, install
@prettier/plugin-ruby
and add it to your configuration:
{
... other settings
"plugins": ["@prettier/plugin-ruby"]
}
Then formatting Ruby files should be possible.
You can provide a default configuration for the prettier via setting the
environment variable PRETTIERD_DEFAULT_CONFIG
to the exact path of the
prettier
configuration file.
If you have locally installed prettier
in your package, it will use that.
Otherwise, it will use the one bundled with the package itself.
If you want to use prettierd exclusively with the locally installed prettier
package, you can set the environment variable PRETTIERD_LOCAL_PRETTIER_ONLY
(any truthy value will do, good examples are true
or 1
).
I use this directly with neovim's LSP client, via efm-langserver:
local prettier = {
formatCommand = 'prettierd "${INPUT}"',
formatStdin = true,
env = {
string.format('PRETTIERD_DEFAULT_CONFIG=%s', vim.fn.expand('~/.config/nvim/utils/linter-config/.prettierrc.json')),
},
}
Alternatively, one can use prettierme to integrate directly with other editors.
Or, as a third option for users of Vim/Neovim plugins such as
formatter.nvim or
vim-codefmt, you can configure
prettierd in the stdin mode. Below is an example with formatter.nvim
:
require('formatter').setup({
logging = false,
filetype = {
javascript = {
-- prettierd
function()
return {
exe = "prettierd",
args = {vim.api.nvim_buf_get_name(0)},
stdin = true
}
end
},
-- other formatters ...
}
})
I don't know much about other editors, but feel free to send a pull requests on instructions.