Package Exports
- prettier-eslint
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (prettier-eslint) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
prettier-eslint
Formats your JavaScript using prettier
followed by eslint --fix
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