Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Support prettier v1.6.0 config (#46) #55

Merged
merged 1 commit into from
Sep 18, 2017

Conversation

kombucha
Copy link
Contributor

I'm not sure if anybody was working on this issue so I made this PR !
Tests are passing, and I tested it on a small example project.

Cheers

@@ -342,12 +337,31 @@ module.exports = {
}
}

if (prettier) {
prettier.clearConfigCache();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too sure about this but it proved necessary when using vscode, otherwise changes to the .prettierrc were not getting picked up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes ESLint a lot slower. I have a partial fix here, but it would be good to figure out a better way to do this: #303

README.md Outdated
@@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Here's a better link for options: https://github.com/prettier/prettier/#options
  • You could change "prettier" to "Prettier" for consistency :)
  • Typo: 0.171.7.0
  • I think it is clearer to say [Prettier configuration file](https://github.com/prettier/prettier/#configuration-file) instead of `.prettierrc` file. Not sure if we need to mention the version at all.
  • The sentence about config file support applies both to the object option and the "fb" option. I suggest moving it outside of all the bullet lists to the very start of the "Options" section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the typos, changed the link and put the sentence about config files outside the sublist, but at the end. WDYT?

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This implementation looks good to me, but can you add tests?

One way to do that would be to put .prettierrc files in a tests/fixtures directory, then add a filename property to an object like this which is also in the same subdirectory, so that the fixture config will be found.

@kombucha
Copy link
Contributor Author

@not-an-aardvark I added three tests :

  • picking up a prettierrc file config
  • overriding it with [object] option
  • overriding it with "fb" option

I had to update the yarn.lock, otherwise tests are failing because prettier is locked to version 1.6.1

Hope that's ok !

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

@not-an-aardvark not-an-aardvark merged commit bc89153 into prettier:master Sep 18, 2017
lencioni added a commit to lencioni/eslint-plugin-prettier that referenced this pull request Jun 11, 2020
At Airbnb we've noticed that the Prettier ESLint rule is extraordinarily
slow. When running ESLint with `TIMING=1`, Prettier is two orders of
magnitude slower than our other slowest rules (which come from
eslint-plugin-import mostly).

I spent some time investigating this today. I ran the Chrome DevTools
profiler while running ESLint on a directory with 480 files in it.
Looking at the flame charts, I noticed that this plugin ended up calling
Prettier's pluginSearchDirs.map.pluginSearchDir for every file that was
being linted, even though it was being memoized. Through some logging, I
determined that the Prettier cache was being cleared between every file,
and narrowed it down to this line, which was added here:

  prettier#55 (comment)

It looks like this cache busting was added to make it so long-running
ESLint processes (e.g. for vscode-eslint) would be able to pick up
changes to prettierrc files without having to reload the process.
Thankfully, we don't use a prettierrc file at Airbnb right now, in favor
of putting our Prettier config inline with our ESLint config. So the
quick performance fix for us is to simply skip the cache busting when
this option is not enabled.

In my profiling, this reduces the time spent in ESLint's verifyAndFix
when running on the same 480 files from 34 seconds to 26 seconds, for a
total savings of 8 seconds.

For folks who are using prettierrc files, this is still pretty crappy,
so it would be great to find a better way to do this. Unfortunately my
knowledge of the inner workings of vscode-eslint and ESLint are not
enough to know if there might be a better way to do this--e.g. maybe
there's some ESLint option that we can respect here?
BPScott pushed a commit that referenced this pull request Jun 14, 2020
At Airbnb we've noticed that the Prettier ESLint rule is extraordinarily
slow. When running ESLint with `TIMING=1`, Prettier is two orders of
magnitude slower than our other slowest rules (which come from
eslint-plugin-import mostly).

I spent some time investigating this today. I ran the Chrome DevTools
profiler while running ESLint on a directory with 480 files in it.
Looking at the flame charts, I noticed that this plugin ended up calling
Prettier's pluginSearchDirs.map.pluginSearchDir for every file that was
being linted, even though it was being memoized. Through some logging, I
determined that the Prettier cache was being cleared between every file,
and narrowed it down to this line, which was added here:

  #55 (comment)

It looks like this cache busting was added to make it so long-running
ESLint processes (e.g. for vscode-eslint) would be able to pick up
changes to prettierrc files without having to reload the process.
Thankfully, we don't use a prettierrc file at Airbnb right now, in favor
of putting our Prettier config inline with our ESLint config. So the
quick performance fix for us is to simply skip the cache busting when
this option is not enabled.

In my profiling, this reduces the time spent in ESLint's verifyAndFix
when running on the same 480 files from 34 seconds to 26 seconds, for a
total savings of 8 seconds.

For folks who are using prettierrc files, this is still pretty crappy,
so it would be great to find a better way to do this. Unfortunately my
knowledge of the inner workings of vscode-eslint and ESLint are not
enough to know if there might be a better way to do this--e.g. maybe
there's some ESLint option that we can respect here?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants