Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

prettier-eslint

1.0.0 • Public • Published

prettier-eslint

Formats your JavaScript using prettier followed by eslint --fix

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

prettier can do some really fantastic automatic formatting. And one of the nice things about it is how opinionated it is. Unfortunately it's either not opinionated enough in some respects and other opinions differ from my own.

This solution

This formats your code via prettier, and then passes the result of that to eslint --fix. This way you can get the benefits of prettier's superior formatting capabilities, but also benefit from the configuration capabilities of eslint.

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev prettier-eslint

Usage

Example

const format = require('prettier-eslint')

// notice, no semicolon in the original text
const sourceCode = 'const {foo} = bar'

const options = {
  text: sourceCode,
  eslintConfig: {
    rules: {
      semi: ['error', 'never'],
    },
  },
  prettierOptions: {
    bracketSpacing: true,
  },
}

const formatted = format(options)

// notice no semicolon in the formatted text
formatted // const { foo } = bar

options

text (String)

The source code to format.

filePath (?String)

The path of the file being formatted can be used in leu of eslintConfig (eslint will be used to find the relevant config for the file).

eslintConfig (?Object)

The config to use for formatting with ESLint. If this is provided, then filePath is not necessary.

prettierOptions (?Object)

The options to pass for formatting with prettier. If not provided, prettier-eslint will attempt to create the options based on the eslintConfig (whether that's provided or derived via filePath.

Inspiration

Other Solutions

None that I'm aware of. Feel free to file a PR if you know of any other solutions.

Contributors

Thanks goes to these people (emoji key):


Kent C. Dodds

💻 📖 🚇 ⚠️

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

LICENSE

MIT

Keywords

none

Install

npm i [email protected]

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar
  • avatar