File tree 2 files changed +21
-7
lines changed
2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -54,8 +54,7 @@ Then, in your `.eslintrc.json`:
54
54
## Options
55
55
56
56
* 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:
59
58
60
59
``` json
61
60
"prettier/prettier" : [" error" , {"singleQuote" : true , "parser" : " flow" }]
@@ -78,6 +77,7 @@ Then, in your `.eslintrc.json`:
78
77
"parser" : " flow"
79
78
}]
80
79
```
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))
81
81
82
82
* The second option:
83
83
Original file line number Diff line number Diff line change @@ -306,11 +306,6 @@ module.exports = {
306
306
]
307
307
} ,
308
308
create ( context ) {
309
- const prettierOptions =
310
- context . options [ 0 ] === 'fb'
311
- ? FB_PRETTIER_OPTIONS
312
- : context . options [ 0 ] ;
313
-
314
309
const pragma = context . options [ 1 ]
315
310
? context . options [ 1 ] . slice ( 1 ) // Remove leading @
316
311
: null ;
@@ -342,12 +337,31 @@ module.exports = {
342
337
}
343
338
}
344
339
340
+ if ( prettier ) {
341
+ prettier . clearConfigCache ( ) ;
342
+ }
343
+
345
344
return {
346
345
Program ( ) {
347
346
if ( ! prettier ) {
348
347
// Prettier is expensive to load, so only load it if needed.
349
348
prettier = require ( 'prettier' ) ;
350
349
}
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
+
351
365
const prettierSource = prettier . format ( source , prettierOptions ) ;
352
366
if ( source !== prettierSource ) {
353
367
const differences = generateDifferences ( source , prettierSource ) ;
You can’t perform that action at this time.
0 commit comments