Skip to content

Commit 478c7e5

Browse files
BPScottnot-an-aardvark
authored andcommittedOct 1, 2018
Breaking: Defining prettier options must use an object
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 `{}`
1 parent 2326231 commit 478c7e5

File tree

4 files changed

+21
-63
lines changed

4 files changed

+21
-63
lines changed
 

‎README.md

+11-28
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ To integrate this plugin with `eslint-config-prettier`, you can use the `"recomm
6060

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

63-
```sh
64-
npm install --save-dev eslint-config-prettier
65-
```
63+
```sh
64+
npm install --save-dev eslint-config-prettier
65+
```
6666

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

69-
```json
70-
{
71-
"extends": ["plugin:prettier/recommended"]
72-
}
73-
```
69+
```json
70+
{
71+
"extends": ["plugin:prettier/recommended"]
72+
}
73+
```
7474

7575
This does three things:
7676

@@ -101,39 +101,22 @@ For the list of every available exclusion rule set, please see the [readme of es
101101
102102
- The first option:
103103

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

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

110-
- Or the string `"fb"` may be used to set "Facebook style" defaults:
111-
112-
```json
113-
"prettier/prettier": ["error", "fb"]
114-
```
115-
116-
Equivalent to:
117-
118-
```json
119-
"prettier/prettier": ["error", {
120-
"singleQuote": true,
121-
"trailingComma": "all",
122-
"bracketSpacing": false,
123-
"jsxBracketSameLine": true,
124-
"parser": "flow"
125-
}]
126-
```
127-
128110
NB: This option will merge and override any config set with `.prettierrc` files
129111

130112
- The second option:
131113

132114
- An object with the following options
115+
133116
- `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.
134117

135118
```json
136-
"prettier/prettier": ["error", null, {
119+
"prettier/prettier": ["error", {}, {
137120
"usePrettierrc": false
138121
}]
139122
```

‎eslint-plugin-prettier.js

+9-26
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ const diff = require('fast-diff');
1515
// Constants
1616
// ------------------------------------------------------------------------------
1717

18-
// Preferred Facebook style.
19-
const FB_PRETTIER_OPTIONS = {
20-
singleQuote: true,
21-
trailingComma: 'all',
22-
bracketSpacing: false,
23-
jsxBracketSameLine: true,
24-
parser: 'flow'
25-
};
26-
2718
const LINE_ENDING_RE = /\r\n|[\r\n\u2028\u2029]/;
2819

2920
const OPERATION_INSERT = 'insert';
@@ -272,21 +263,16 @@ module.exports = {
272263
schema: [
273264
// Prettier options:
274265
{
275-
anyOf: [
276-
{ enum: [null, 'fb'] },
277-
{ type: 'object', properties: {}, additionalProperties: true }
278-
]
266+
type: 'object',
267+
properties: {},
268+
additionalProperties: true
279269
},
280270
{
281-
anyOf: [
282-
{
283-
type: 'object',
284-
properties: {
285-
usePrettierrc: { type: 'boolean' }
286-
},
287-
additionalProperties: true
288-
}
289-
]
271+
type: 'object',
272+
properties: {
273+
usePrettierrc: { type: 'boolean' }
274+
},
275+
additionalProperties: true
290276
}
291277
]
292278
},
@@ -308,10 +294,7 @@ module.exports = {
308294
prettier = require('prettier');
309295
}
310296

311-
const eslintPrettierOptions =
312-
context.options[0] === 'fb'
313-
? FB_PRETTIER_OPTIONS
314-
: context.options[0];
297+
const eslintPrettierOptions = context.options[0] || {};
315298

316299
const prettierRcOptions = usePrettierrc
317300
? prettier.resolveConfig.sync(filepath, {

‎test/invalid/11-b.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var a = {
99
};
1010

1111
OPTIONS:
12-
[null]
12+
[{}]
1313

1414
ERRORS:
1515
[

‎test/prettier.js

-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ ruleTester.run('prettier', rule, {
3131
valid: [
3232
// Correct style.
3333
{ code: '"";\n' },
34-
// Facebook style uses single quotes.
35-
{ code: `('');\n`, options: ['fb'] },
3634
// Single quote from .prettierrc.
3735
{ code: `'';\n`, filename: getPrettierRcJsFilename('single-quote') },
3836
// Override .prettierrc from object option.
@@ -41,12 +39,6 @@ ruleTester.run('prettier', rule, {
4139
filename: getPrettierRcJsFilename('bracket-spacing'),
4240
options: [{ bracketSpacing: false }]
4341
},
44-
// Override .prettierrc from facebook option.
45-
{
46-
code: `('');\n`,
47-
filename: getPrettierRcJsFilename('double-quote'),
48-
options: ['fb']
49-
},
5042
// Only use options from plugin, skipping .prettierrc
5143
{
5244
code: `var foo = {bar: 0};\n`,

0 commit comments

Comments
 (0)
Please sign in to comment.