Code Monkey home page Code Monkey logo

eslint-plugin-prettier's Introduction

eslint-plugin-prettier Build Status

Runs Prettier as an ESLint rule and reports differences as individual ESLint issues.

Sample

error: Insert `,` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:22:25:
  20 | import {
  21 |   observeActiveEditorsDebounced,
> 22 |   editorChangesDebounced
     |                         ^
  23 | } from './debounced';;
  24 |
  25 | import {observableFromSubscribeFunction} from '../commons-node/event';


error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:23:21:
  21 |   observeActiveEditorsDebounced,
  22 |   editorChangesDebounced
> 23 | } from './debounced';;
     |                     ^
  24 |
  25 | import {observableFromSubscribeFunction} from '../commons-node/event';
  26 | import {cacheWhileSubscribed} from '../commons-node/observable';


2 errors found.

./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js (code from nuclide).

Installation

npm install --save-dev prettier eslint-plugin-prettier

eslint-plugin-prettier does not install Prettier or ESLint for you. You must install these yourself.

Then, in your .eslintrc.json:

{
  "plugins": [
    "prettier"
  ],
  "rules": {
    "prettier/prettier": "error"
  }
}

Options

  • The first option:

    • Objects are passed directly to Prettier as options. Example:

      "prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
    • Or the string "fb" may be used to set "Facebook style" defaults:

      "prettier/prettier": ["error", "fb"]

      Equivalent to:

      "prettier/prettier": ["error", {
        "singleQuote": true,
        "trailingComma": "all",
        "bracketSpacing": false,
        "jsxBracketSameLine": true,
        "parser": "flow"
      }]

    NB: This option will merge and override any config set with .prettierrc files (for Prettier < 1.7.0, config files are ignored)

  • The second option:

    • A string with a pragma that triggers this rule. By default, this rule applies to all files. However, if you set a pragma (this option), only files with that pragma in the heading docblock will be checked. All pragmas must start with @. Example:

      "prettier/prettier": ["error", null, "@prettier"]

      Only files with @prettier in the heading docblock will be checked:

      /** @prettier */
      
      console.log(1 + 2 + 3);

      Or:

      /**
       * @prettier
       */
      
      console.log(4 + 5 + 6);

      This option is useful if you're migrating a large codebase and already use pragmas like @flow.

  • The rule is autofixable -- if you run eslint with the --fix flag, your code will be formatted according to prettier style.


This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect patterns in the AST. (If another active ESLint rule disagrees with prettier about how code should be formatted, it will be impossible to avoid lint errors.) You can use eslint-config-prettier to disable all formatting-related ESLint rules. If your desired formatting does not match the prettier output, you should use a different tool such as prettier-eslint instead.

Contributing

See CONTRIBUTING.md

eslint-plugin-prettier's People

Contributors

ikatyang avatar josephfrazier avatar kombucha avatar louim avatar lydell avatar not-an-aardvark avatar oieduardorabelo avatar rootulp avatar sapegin avatar simenb avatar zertosh 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.