prettier-eslint-cli

CLI for prettier-eslint
授权协议 MIT License
开发语言 JavaScript
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 邹博裕
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

prettier-eslint-cli

CLI for prettier-eslint

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 useprettier-eslint on one or multiple files. prettier-eslint-cli forwards on the filePathand other relevant options to prettier-eslint which identifies the applicable ESLintconfig 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 shouldbe 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 CLIis 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]

Prefix an option with "no-" to set it to false, such as --no-semi to
disable semicolons and --no-eslint-ignore to disable default ignores.

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]
  --stdin-filepath         Path to the file to pretend that stdin comes from.
  --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]
  --prettier-ignore        Only format matching files even if they are not
                           ignored by .prettierignore. (can use
                           --no-prettier-ignore to disable this)
                                                       [boolean] [default: true]
  --list-different         Print filenames of files that are different from
                           Prettier + Eslint formatting.
                                                      [boolean] [default: false]
  --eslint-path            The path to the eslint module to use
                 [default: "./node_modules/eslint"]
  --eslint-config-path     Path to the eslint config to use for eslint --fix
  --prettier-path          The path to the prettier module to use [default: "./node_modules/prettier"]
  --config                 Path to the prettier config
  --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]
  --use-tabs               Indent lines with tabs instead of spaces.   [boolean]
  --print-width            Specify the length of line that the printer will wrap
                           on.                                          [number]
  --tab-width              Specify the number of spaces per indentation-level.
                                                                        [number]
  --trailing-comma         Print trailing commas wherever possible.

                           Valid options:
                           - "none" - no trailing commas
                           - "es5" - trailing commas where valid in ES5
                           (objects, arrays, etc)
                           - "all" - trailing commas wherever possible (function
                           arguments)   [string] [choices: "none", "es5", "all"]
  --bracket-spacing        Print spaces between brackets in object literals.
                           Can use --no-bracket-spacing for "false" to disable
                           it.

                           Valid options:
                           - true - Example: { foo: bar }
                           - false - Example: {foo: bar}               [boolean]
  --jsx-bracket-same-line  Put the > of a multi-line JSX element at the end of
                           the last line instead of being alone on the next line
                                                                       [boolean]
  --parser                 Specify which parser to use.                 [string]
  --semi                   Print semicolons at the ends of statements.
                           Can use --no-semi.

                           Valid options:
                           - true - add a semicolon at the end of every
                           statement
                           - false - only add semicolons at the beginning of
                           lines that may introduce ASI failures       [boolean]
  --single-quote           Use single quotes instead of double quotes. [boolean]

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 provideincludes the string node_modules.

--write

By default prettier-eslint will simply log the formatted version to the terminal. If you want to overwrite the fileitself (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 committedbefore running prettier-eslint --write as it will overwrite your files!

--list-different

Instead of printing the formatted version of the files to the terminal, prettier-eslint will log the name of the files that are different from the expected formatting. This can be usefull when using prettier-eslint in a version control system hook to inform the committer which files need to be formatted.

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

--eslint-config-path

Resolve eslint config file, parse and forward config object as the eslintConfig option toprettier-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. Bydefault, 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 ifyou 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 theargument --prettier-last, it will run eslint --fix first, then prettier. This allows you touse eslint to look for bugs and/or bad practices, and use prettier to enforce code style.

prettier options

prettier-eslint-cli also supports the same command line options as prettier.

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

Refer to the prettier-eslint docs for documentation on these options

Integration

Any linter that support ESLint CLIEngine interface can be integrate with prettier-eslint

Knowed integrated package helpers

Standalone CLI tools based on prettier-eslint-cli

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

�� ⚠️

Matteo Ronchi

�� ��

Benoît Zugmeyer

�� ⚠️

Charlike Mike Reagent

�� ⚠️

Dion Dirza

��

mrm007

�� ��

Jack Franklin

��

Ryan Zimmerman

��

Paolo Moretti

�� �� ⚠️

bySabi Files

�� ��

Pavel Pertsev

�� ⚠️

Josh English

⚠️ �� �� ��

Spenser Isdahl

�� �� ⚠️

Björn Dalfors

��

Steven Scaffidi

��

Daniel Wilhelmsen

�� ��

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

LICENSE

MIT

  • 浅谈EditorConfig、Prettier以及Eslint的使用 EditorConfig、Prettier以及Eslint都用于实现前端代码规范化的工具,它们的功能分别如下:  EditorConfig: 专注于统一编辑器编码风格配置  Prettier: 专注于检查并自动更正代码风格,美化代码  Eslint: 专注于 JavaScript 代码质量检查, 编码风格约束等 下面将简要

  • by Abhishek Jain 通过阿比舍克·Ja那 如何将Prettier与ESLint和stylelint集成 (How to integrate Prettier with ESLint and stylelint) 或如何再也不用担心代码样式 (or How to never worry about code styling again) ESLint and stylelint are

  • 前端代码规范配置 参考来源:https://blog.csdn.net/u013361179/article/details/108885859 前言 eslint的作用:eslint作用是按照一定规则,检测代码质量; prettier的作用:prettier起到的作用是按照统一风格去美化代码 目前支持的格式: javascript、jsx、ts、tsx flow json css、less、sc

  • 项目规范如何生成 项目地址 虽然现在很多脚手架都能帮我们自动生成和配置好,但是我觉得还是有必要手动实现下 代码风格格式化配置(prettier) 1 yarn add --dev --exact prettier 2 新建文件 .prettierrc.js .prettierignore 3 在这两个文件中配置规则 和 需要忽略的文件 4 package.json中配置脚本 "prettier":

  • 1、vue create 项目名创建项目时选择自定义创建,会询问你是否安装eslint,我选择了ESLint + Prettier方式;他会默认下载 “eslint”,“babel-eslint”,“eslint-plugin-prettier”,“eslint-plugin-vue”,"@vue/eslint-config-prettier"等插件 2、创建项目时你会选择1种直接在package

  • module.exports = { root: true, parserOptions: { parser: 'babel-eslint', sourceType: 'module' }, env: { browser: true, node: true, es6: true, }, // extends: ['plugin:vue

  • module.exports = { root: true, env: { node: true, 'vue/setup-compiler-macros': true, }, extends: [ 'plugin:vue/essential', '@vue/eslint-config-typescript/recommended', 'plu

 相关资料
  • prettier-eslint (for Atom) DEPRECATED This plugin has been merged with the official prettier-atom plugin. Uninstall prettier-eslint and install prettier-atom. Then enable the ESLint integration: Atom

  • VSCode,eslint 报错 Delete ↹eslint (prettier/prettier)? 这个要怎么改?

  • 查资料说是配置"prettier.vueIndentScriptAndStyle": true, 但在vscode的设置中配置后依然无效,求解 语言是vue+ts

  • 每次打开文件保存ESLint都会出现以下错误: 当我添加新行,它删除它,仍然显示这个错误。 如何防止WebStorm中的ESLint错误?

  • Prettier 是一个“有主见”的代码格式化工具,支持列表如下: JavaScript,包括 ES2017 JSX Flow TypeScript CSS、LESS 和 SCSS JSON GraphQL 简而言之,这个工具能够使输出代码保持风格一致。 示例: 举个例子,对于下面这行代码: foo(arg1, arg2, arg3, arg4); 它适合在同一行显示。但是我们经常会遇到的代码是这

  • 本文向大家介绍vue项目中使用eslint+prettier规范与检查代码的方法,包括了vue项目中使用eslint+prettier规范与检查代码的方法的使用技巧和注意事项,需要的朋友参考一下 1.前言   在团队协作中,为避免低级 Bug、以及团队协作时不同代码风格对彼此造成的困扰与影响,会预先制定编码规范。使用 Lint 工具和代码风格检测工具,则可以辅助编码规范执行,有效控制代码质量。Es