Skip to content

Commit 2aa0cd3

Browse files
committed
Fix: Support prettier v1.6.0 config (#46)
1 parent 95f0808 commit 2aa0cd3

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ Then, in your `.eslintrc.json`:
5454
## Options
5555

5656
* The first option:
57-
58-
- Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#api). Example:
57+
- Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#options). Example:
5958

6059
```json
6160
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
@@ -78,6 +77,7 @@ Then, in your `.eslintrc.json`:
7877
"parser": "flow"
7978
}]
8079
```
80+
NB: This option will merge and override any config set with `.prettierrc` files (for Prettier < 1.7.0, [config files are ignored](https://github.com/prettier/eslint-plugin-prettier/issues/46))
8181

8282
* The second option:
8383

eslint-plugin-prettier.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,6 @@ module.exports = {
306306
]
307307
},
308308
create(context) {
309-
const prettierOptions =
310-
context.options[0] === 'fb'
311-
? FB_PRETTIER_OPTIONS
312-
: context.options[0];
313-
314309
const pragma = context.options[1]
315310
? context.options[1].slice(1) // Remove leading @
316311
: null;
@@ -342,12 +337,31 @@ module.exports = {
342337
}
343338
}
344339

340+
if (prettier) {
341+
prettier.clearConfigCache();
342+
}
343+
345344
return {
346345
Program() {
347346
if (!prettier) {
348347
// Prettier is expensive to load, so only load it if needed.
349348
prettier = require('prettier');
350349
}
350+
351+
const eslintPrettierOptions =
352+
context.options[0] === 'fb'
353+
? FB_PRETTIER_OPTIONS
354+
: context.options[0];
355+
const prettierRcOptions =
356+
prettier.resolveConfig && prettier.resolveConfig.sync
357+
? prettier.resolveConfig.sync(context.getFilename())
358+
: null;
359+
const prettierOptions = Object.assign(
360+
{},
361+
prettierRcOptions,
362+
eslintPrettierOptions
363+
);
364+
351365
const prettierSource = prettier.format(source, prettierOptions);
352366
if (source !== prettierSource) {
353367
const differences = generateDifferences(source, prettierSource);

0 commit comments

Comments
 (0)