Skip to content

Commit

Permalink
Breaking: Defining prettier options must use an object
Browse files Browse the repository at this point in the history
Drop support for specifying prettier options using the "fb" shorthand
string. Replace "fb" with either config in your .prettierrc or the object:
`{ singleQuote: true, trailingComma: 'all', bracketSpacing: false, jsxBracketSameLine: true, parser: 'flow'}`

Drop support for specifying the prettier options as `null`. Replace
`null` with an empty object `{}`
  • Loading branch information
BPScott authored and not-an-aardvark committed Oct 1, 2018
1 parent 2326231 commit 478c7e5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 63 deletions.
39 changes: 11 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ To integrate this plugin with `eslint-config-prettier`, you can use the `"recomm

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

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

2. Then you need to add `plugin:prettier/recommended` as the last extension in your `.eslintrc.json`:

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

This does three things:

Expand Down Expand Up @@ -101,39 +101,22 @@ For the list of every available exclusion rule set, please see the [readme of es

- The first option:

- Objects are passed directly to Prettier as [options](https://prettier.io/docs/en/options.html). Example:
- An object representing [options](https://prettier.io/docs/en/options.html) that will be passed into prettier. Example:

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

- Or the string `"fb"` may be used to set "Facebook style" defaults:

```json
"prettier/prettier": ["error", "fb"]
```

Equivalent to:

```json
"prettier/prettier": ["error", {
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false,
"jsxBracketSameLine": 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.

```json
"prettier/prettier": ["error", null, {
"prettier/prettier": ["error", {}, {
"usePrettierrc": false
}]
```
Expand Down
35 changes: 9 additions & 26 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ const diff = require('fast-diff');
// Constants
// ------------------------------------------------------------------------------

// Preferred Facebook style.
const FB_PRETTIER_OPTIONS = {
singleQuote: true,
trailingComma: 'all',
bracketSpacing: false,
jsxBracketSameLine: true,
parser: 'flow'
};

const LINE_ENDING_RE = /\r\n|[\r\n\u2028\u2029]/;

const OPERATION_INSERT = 'insert';
Expand Down Expand Up @@ -272,21 +263,16 @@ module.exports = {
schema: [
// Prettier options:
{
anyOf: [
{ enum: [null, 'fb'] },
{ type: 'object', properties: {}, additionalProperties: true }
]
type: 'object',
properties: {},
additionalProperties: true
},
{
anyOf: [
{
type: 'object',
properties: {
usePrettierrc: { type: 'boolean' }
},
additionalProperties: true
}
]
type: 'object',
properties: {
usePrettierrc: { type: 'boolean' }
},
additionalProperties: true
}
]
},
Expand All @@ -308,10 +294,7 @@ module.exports = {
prettier = require('prettier');
}

const eslintPrettierOptions =
context.options[0] === 'fb'
? FB_PRETTIER_OPTIONS
: context.options[0];
const eslintPrettierOptions = context.options[0] || {};

const prettierRcOptions = usePrettierrc
? prettier.resolveConfig.sync(filepath, {
Expand Down
2 changes: 1 addition & 1 deletion test/invalid/11-b.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var a = {
};

OPTIONS:
[null]
[{}]

ERRORS:
[
Expand Down
8 changes: 0 additions & 8 deletions test/prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ ruleTester.run('prettier', rule, {
valid: [
// Correct style.
{ code: '"";\n' },
// Facebook style uses single quotes.
{ code: `('');\n`, options: ['fb'] },
// Single quote from .prettierrc.
{ code: `'';\n`, filename: getPrettierRcJsFilename('single-quote') },
// Override .prettierrc from object option.
Expand All @@ -41,12 +39,6 @@ ruleTester.run('prettier', rule, {
filename: getPrettierRcJsFilename('bracket-spacing'),
options: [{ bracketSpacing: false }]
},
// Override .prettierrc from facebook option.
{
code: `('');\n`,
filename: getPrettierRcJsFilename('double-quote'),
options: ['fb']
},
// Only use options from plugin, skipping .prettierrc
{
code: `var foo = {bar: 0};\n`,
Expand Down

0 comments on commit 478c7e5

Please sign in to comment.