Socket
Socket
Sign inDemoInstall

eslint-plugin-prettier

Package Overview
Dependencies
154
Maintainers
1
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
1
Install size
20.0 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

v2.0.1 (2017-02-26)

  • Docs: add travis badge to README.md (1daa495)
  • Upgrade: prettier to 0.18.0 (1700e41)
  • Chore: use eslint-config-prettier (c979b84)
  • Fix: avoid relying on an internal eslint function (5296930)
  • Docs: mention eslint-config-prettier in README.md (3fd855d)
  • Chore: pin the version of prettier used to lint this module (refs #1) (db85633)

Readme

Source

eslint-plugin-prettier Build Status

Runs prettier as an eslint rule

Installation

You'll first need to install ESLint:

$ npm install eslint --save-dev

Next, install eslint-plugin-prettier:

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

Finally, install prettier:

$ npm install prettier --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-prettier globally.

Usage

Add prettier to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "prettier"
    ]
}

Then configure the prettier rule under the rules section:

{
    "rules": {
        "prettier/prettier": "error"
    }
}

You can also pass prettier configuration as an option:

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

The rule will report an error if your code does not match prettier style. 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 (e.g. if you don't want semicolons), you should use a different tool such as prettier-eslint instead.

Migrating to 2.0.0

Starting in 2.0.0, prettier is a peerDependency of this module, rather than a dependency. This means that you can use any version of prettier with this plugin, but it also means that you need to install it separately and include it as a devDependency in your project.

To install prettier, use:

npm install prettier --save-dev

Keywords

FAQs

Last updated on 26 Feb 2017

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