agarrharr / prettier-eslint-cli

CLI for prettier-eslint

Home Page:https://www.npmjs.com/package/prettier-eslint-cli

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

prettier-eslint-cli

CLI for prettier-eslint

Build Status Code Coverage Dependencies version downloads MIT License

All Contributors PRs Welcome Donate Code of Conduct Roadmap Examples

Watch on GitHub Star on GitHub Tweet

The problem

You have a bunch of files that you want to format using prettier-eslint. But prettier-eslint can only operate on strings.

This solution

This is a CLI that allows you to use prettier-eslint on one or multiple files. prettier-eslint-cli forwards on the filePath and other relevant options to prettier-eslint which identifies the applicable ESLint config for each file and uses that to determine the options for prettier and eslint --fix.

Installation

This module is distributed via npm which is bundled with node and should be installed (with yarn) as one of your project's devDependencies:

yarn add --dev prettier-eslint-cli

If you're still using the npm client: npm install --save-dev prettier-eslint-cli

Usage

Typically you'll use this in your npm scripts (or package scripts):

{
  "scripts": {
    "format": "prettier-eslint src/**/*.js"
  }
}

This will format all .js files in the src directory. The argument you pass to the CLI is a glob and you can pass as many as you wish. You can also pass options.

Vim

Vim users can add the following to their .vimrc:

autocmd FileType javascript set formatprg=prettier-eslint\ --stdin

This makes prettier-eslint-cli power the gq command for automatic formatting without any plugins. You can also add the following to your .vimrc to run prettier-eslint-cli when .js files are saved:

autocmd BufWritePre *.js :normal gggqG

CLI Options

prettier-eslint --help
Usage: prettier-eslint <globs>... [--option-1 option-1-value --option-2]

Options:
  -h, --help      Show help                                            [boolean]
  --version       Show version number                                  [boolean]
  --write         Edit the file in-place (beware!)              [default: false]
  --stdin         Read input via stdin                          [default: false]
  --eslintPath    The path to the eslint module to use
    [default: "<your_project>/node_modules/eslint"]
  --prettierPath  The path to the prettier module to use
  [default: "<your_project>/node_modules/prettier"]
  --log           Show logs                                     [default: false]
  --sillyLogs     Show silly amount of logs (good for debugging)[default: false]

Any number of globs you wish to use to match the files you wish to format. By default, glob will ignore **/node_modules/** unless the glob you provide includes the string node_modules.

--write

By default prettier-eslint will simply log the formatted version to the terminal. If you want to overwrite the file itself (a common use-case) then add --write.

NOTE: It is recommended that you keep your files under source control and committed before running prettier-eslint --write as it will overwrite your files!

--stdin

Accept input via stdin. For example:

echo "var   foo =    'bar'" | prettier-eslint --stdin
# results in: "var foo = 'bar';" (depending on your eslint config)

--eslint-path

Forwarded as the eslintPath option to prettier-eslint

--prettier-path

Forwarded as the prettierPath option to prettier-eslint

--log

If prettier-eslint encounters an error formatting a file, it logs an error to the console. prettier-eslint-cli disables this behavior by default. You can turn it on with --log.

--silly-logs

This will be forwarded onto prettier-eslint as (sillyLogs) and is useful for debugging.

Related

Contributors

Thanks goes to these people (emoji key):


Kent C. Dodds

πŸ’» πŸ“– πŸš‡ ⚠️

Adam Harris

πŸ‘€

Eric McCormick

πŸ‘€

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

About

CLI for prettier-eslint

https://www.npmjs.com/package/prettier-eslint-cli

License:MIT License


Languages

Language:JavaScript 100.0%