Coder Social home page Coder Social logo

cef62 / prettier-eslint-cli Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prettier/prettier-eslint-cli

0.0 2.0 0.0 354 KB

CLI for prettier-eslint

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

License: MIT License

JavaScript 100.00%

prettier-eslint-cli's Introduction

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!)   [boolean] [default: false]
  --stdin          Read input via stdin               [boolean] [default: false]
  --eslint-ignore  Only format matching files even if they are not ignored by
                   .eslintignore. (can use --no-eslint-ignore to disable this)
                                                       [boolean] [default: true]
  --eslintPath     The path to the eslint module to use
    [default: "<path-to-root>/node_modules/eslint"]
  --prettierPath   The path to the prettier module to use
  [default: "<path-to-root>/node_modules/prettier"]
  --ignore         pattern(s) you wish to ignore (can be used multiple times and
                   includes **/node_modules/** automatically)
  --log-level, -l  The log level to use
        [choices: "silent", "error", "warn", "info", "debug", "trace"] [default:
                                                                         "warn"]
  --prettier-last  Run prettier last                  [boolean] [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. You should quote your globs, otherwise your terminal will expand the glob before it gets to prettier-eslint (which can have unexpected results):

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

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-level

Forwarded as logLevel option to prettier-eslint

--no-eslint-ignore

Disables application of .eslintignore to the files resolved from the glob. By default, prettier-eslint-cli will exclude files if they are matched by a .eslintignore. Add this flag to disable this behavior.

Note: You can also set the LOG_LEVEL environment variable to control logging in prettier-eslint

--prettier-last

By default, prettier-eslint-cli will run prettier first, then eslint --fix. This is great if you want to use prettier, but override some of the styles you don't like using eslint --fix.

An alternative approach is to use different tools for different concerns. If you provide the argument --pretter-last, it will run eslint --fix first, then prettier. This allows you to use eslint to look for bugs and/or bad practices, and use prettier to enforce code style.

--prettier

Passes prettier configuration options to prettier-eslint, such as trailingComma or singleQuote, using the dot-notation.

For example: prettier-eslint --prettier.trailing-comma es5

The options supported are the same as prettier-eslint

Related

Contributors

Thanks goes to these people (emoji key):


Kent C. Dodds

๐Ÿ’ป ๐Ÿ“– ๐Ÿš‡ โš ๏ธ

Adam Harris

๐Ÿ’ป ๐Ÿ“– ๐Ÿ‘€

Eric McCormick

๐Ÿ‘€

Joel Sequeira

๐Ÿ“–

Frank Taillandier


Adam Stankiewicz

๐Ÿ’ป

Stephen John Sorensen

๐Ÿ’ป

Gandem

๐Ÿ’ป โš ๏ธ

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

LICENSE

MIT

prettier-eslint-cli's People

Contributors

aaronjensen avatar aharris88 avatar denis-sokolov avatar dirtyf avatar gandem avatar greenkeeper[bot] avatar joelseq avatar sheerun avatar spudly avatar

Watchers

 avatar  avatar

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.