Socket
Socket
Sign inDemoInstall

eslint-plugin-prettier

Package Overview
Dependencies
91
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eslint-plugin-prettier

Runs prettier as an eslint rule


Version published
Maintainers
2
Install size
81.1 kB
Created

Package description

What is eslint-plugin-prettier?

The eslint-plugin-prettier npm package integrates Prettier, an opinionated code formatter, with ESLint, a tool for identifying and reporting on patterns in JavaScript. It allows you to use Prettier as an ESLint rule and reports differences as individual ESLint issues.

What are eslint-plugin-prettier's main functionalities?

Code Formatting

Automatically format code to match the style specified in your Prettier configuration when you run ESLint with the --fix option.

"scripts": { "lint": "eslint --fix 'src/**/*.js'" }

Integration with ESLint Rules

Use Prettier to enforce a consistent code style while still using ESLint to catch possible errors.

{ "extends": ["plugin:prettier/recommended"] }

Customizable Formatting Rules

Override default Prettier options to tailor the formatting to your project's needs.

{ "rules": { "prettier/prettier": ["error", { "singleQuote": true, "parser": "flow" }] } }

Other packages similar to eslint-plugin-prettier

Changelog

Source

v3.0.1 (2018-12-28)

  • Catch and format SyntaxErrors as eslint violations (#141) (4a0e57d)
  • build(deps-dev): bump eslint from 5.11.0 to 5.11.1 (d34daed)
  • build(deps-dev): bump eslint from 5.10.0 to 5.11.0 (7f4f45d)
  • build(deps-dev): bump eslint-plugin-eslint-plugin from 2.0.0 to 2.0.1 (5be3bcf)
  • build(deps-dev): bump eslint from 5.9.0 to 5.10.0 (11e7c44)
  • build(deps-dev): bump eslint-plugin-eslint-plugin from 1.4.1 to 2.0.0 (9e5bf14)
  • build(deps-dev): bump vue-eslint-parser from 4.0.2 to 4.0.3 (234583a)
  • build(deps-dev): bump vue-eslint-parser from 3.3.0 to 4.0.2 (8675d57)
  • Upgrade: Bump vue-eslint-parser from 3.2.2 to 3.3.0 (2379e93)
  • Upgrade: Bump eslint-config-prettier from 3.1.0 to 3.3.0 (3ea0021)
  • Upgrade: Bump eslint from 5.8.0 to 5.9.0 (c774fb8)
  • build(deps-dev): bump eslint-plugin-node from 7.0.1 to 8.0.0 (#121) (2a4fba0)
  • build(deps-dev): bump eslint-plugin-eslint-plugin from 1.4.0 to 1.4.1 (#120) (29caa29)
  • build(deps-dev): bump eslint from 5.6.0 to 5.8.0 (#119) (2836350)

Readme

Source

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 eslint-plugin-prettier
npm install --save-dev --save-exact 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"
  }
}

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.

To integrate this plugin with eslint-config-prettier, you can use the "recommended" configuration:

  1. In addition to the above installation instructions, install eslint-config-prettier:

    npm install --save-dev eslint-config-prettier
    
  2. Then you need to add plugin:prettier/recommended as the last extension in your .eslintrc.json:

    {
      "extends": ["plugin:prettier/recommended"]
    }
    

This does three things:

  • Enables eslint-plugin-prettier.
  • Sets the prettier/prettier rule to "error".
  • Extends the eslint-config-prettier configuration.

You can then set Prettier's own options inside a .prettierrc file.

  1. In order to support special ESLint plugins (e.g. eslint-plugin-react), add extra exclusions for the plugins you use like so:
{
  "extends": [
    "plugin:prettier/recommended",
    "prettier/flowtype",
    "prettier/react",
    "prettier/standard"
  ]
}

For the list of every available exclusion rule set, please see the readme of eslint-config-prettier.

Options

Note: While it is possible to pass options to Prettier via your ESLint configuration file, it is not recommended because editor extensions such as prettier-atom and prettier-vscode will read .prettierrc, but won't read settings from ESLint, which can lead to an inconsistent experience.

  • The first option:

    • An object representing options that will be passed into prettier. Example:

      "prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
      

      NB: This option will merge and override any config set with .prettierrc files

  • The second option:

    • An object with the following options

      • usePrettierrc: Enables loading of the Prettier configuration file, (default: true). May be useful if you are using multiple tools that conflict with each other, or do not wish to mix your ESLint settings with your Prettier configuration.

        "prettier/prettier": ["error", {}, {
          "usePrettierrc": false
        }]
        
  • The rule is autofixable -- if you run eslint with the --fix flag, your code will be formatted according to prettier style.


Contributing

See CONTRIBUTING.md

Keywords

FAQs

Last updated on 28 Dec 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc