Skip to content

Commit

Permalink
Fix: Support prettier v1.6.0 config (prettier#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
kombucha committed Sep 17, 2017
1 parent 95f0808 commit 77799d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Then, in your `.eslintrc.json`:

* The first option:

- Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#api). Example:
- Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#api). This plugin will merge and override any config set with a `.prettierrc` file (only for prettier >= 0.17). Example:

```json
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
Expand Down
24 changes: 19 additions & 5 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,6 @@ module.exports = {
]
},
create(context) {
const prettierOptions =
context.options[0] === 'fb'
? FB_PRETTIER_OPTIONS
: context.options[0];

const pragma = context.options[1]
? context.options[1].slice(1) // Remove leading @
: null;
Expand Down Expand Up @@ -342,12 +337,31 @@ module.exports = {
}
}

if (prettier) {
prettier.clearConfigCache();
}

return {
Program() {
if (!prettier) {
// Prettier is expensive to load, so only load it if needed.
prettier = require('prettier');
}

const eslintPrettierOptions =
context.options[0] === 'fb'
? FB_PRETTIER_OPTIONS
: context.options[0];
const prettierRcOptions =
prettier.resolveConfig && prettier.resolveConfig.sync
? prettier.resolveConfig.sync(context.getFilename())
: null;
const prettierOptions = Object.assign(
{},
prettierRcOptions,
eslintPrettierOptions
);

const prettierSource = prettier.format(source, prettierOptions);
if (source !== prettierSource) {
const differences = generateDifferences(source, prettierSource);
Expand Down

0 comments on commit 77799d5

Please sign in to comment.