GithubHelp home page GithubHelp logo

sqve / prettierd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fsouza/prettierd

0.0 1.0 0.0 1.01 MB

prettier, as a daemon, for ludicrous formatting speed.

License: ISC License

TypeScript 99.21% JavaScript 0.79%

prettierd's Introduction

prettierd

Build Status

Wanna run prettier in your editor, but fast? Welcome to prettierd!

This is built on top of core_d.js and integrates with prettier.

Installation guide

$ npm install -g @fsouza/prettierd

NOTE: npm comes builtin to node.

Using in the command line with node.js

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

Using with TCP (moar speed)

Following the instructions from https://github.com/mantoni/core_d.js#moar-speed:

$ PORT=`cat ~/.prettierd | cut -d" " -f1`
$ TOKEN=`cat ~/.prettierd | cut -d" " -f2`
$ echo "$TOKEN $PWD file.ts" | cat - file.ts | nc localhost $PORT

Supported languages / plugins

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

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.

Provide Default Configuration

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.

Local Instance

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).

Editor integration

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')),
  },
}

The native TCP client can be used too, I used to do it migrated to efm-langserver for simplicity, see more details in this blog post or my configuration.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.