Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

New: Add 'recommended' configuration #73

Merged
merged 1 commit into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.j
## Installation

```sh
npm install --save-dev prettier eslint-plugin-prettier
npm install --save-dev eslint-plugin-prettier
npm install --save-dev --save-exact prettier
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact installation is recommended for prettier https://prettier.io/docs/en/install.html

```

**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._
Expand All @@ -51,10 +52,44 @@ Then, in your `.eslintrc.json`:
}
```

## Recommended Configuration

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](https://github.com/prettier/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](https://github.com/prettier/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`:

```sh
npm install --save-dev eslint-config-prettier
```

2. Then all you need in your `.eslintrc.json` is:

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

This does three things:

1. Enables `eslint-plugin-prettier`.
2. Sets the `prettier/prettier` rule to `"error"`.
3. Extends the `eslint-config-prettier` configuration.

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

## 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`](https://prettier.io/docs/en/configuration.html), but **won't** read settings from ESLint, which can lead to an inconsistent experience.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a sidenote: I was under the impression that people using eslint-plugin-prettier would just use editor integrations for eslint, because it wouldn't be necessary to use integrations for prettier. Is it common for people to use prettier-atom along with eslint-plugin-prettier?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally use prettier-vscode with eslint-plugin-prettier. I don't use use the vscode-eslint plugin's format on save capabilities as Prettier covers a wider range of languages, and I find it a bit faster.


* The first option:
- Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#options). Example:
- Objects are passed directly to Prettier as [options](https://prettier.io/docs/en/options.html). Example:

```json
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
Expand Down Expand Up @@ -111,8 +146,6 @@ Then, in your `.eslintrc.json`:

---

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](https://github.com/prettier/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](https://github.com/prettier/prettier-eslint) instead.

## Contributing

See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)
9 changes: 9 additions & 0 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ function reportReplace(context, offset, deleteText, insertText) {
module.exports = {
showInvisibles,
generateDifferences,
configs: {
recommended: {
extends: ['prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error'
}
}
},
rules: {
prettier: {
meta: {
Expand Down