Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Implement Prettier Config #261

Merged
merged 5 commits into from
Sep 15, 2017
Merged

Implement Prettier Config #261

merged 5 commits into from
Sep 15, 2017

Conversation

robwise
Copy link
Collaborator

@robwise robwise commented Sep 4, 2017

No description provided.

@MrLoh
Copy link

MrLoh commented Sep 4, 2017

can't wait for this, thanks a lot for the hard work

@darahak
Copy link
Collaborator

darahak commented Sep 4, 2017

We should consider commiting transpiled files separately. It's a bit difficult to navigate and review big changes.
We can update the contributing guides accordingly.

Copy link
Collaborator

@darahak darahak left a comment

Choose a reason for hiding this comment

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

I think we should keep formatting options and EditorConfig support (see comments).

For the rest, it totally makes sense to drop them in favor of the new config file.

I didn't look at the code specifically. I think the tests should be reliable enough for this kind of refactoring.

@@ -1,40 +0,0 @@
// @flow
Copy link
Collaborator

Choose a reason for hiding this comment

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

I might have misunderstood, but isn't this the feature that lets the package use local Prettier installs instead of the packaged one? I thought it was useful for a lot of devs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the one that determines whether or not to run formatOnSave based on whether prettier is installed, if the user has chosen the option. The code that gets the local instance is still in (that's getPrettierInstance).

const handleError = require('./handleError');

const executePrettier = (editor: TextEditor, text: string) =>
getPrettierInstance(editor).format(text, buildPrettierOptions(editor));
getPrettierInstance(editor)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I totally missed that point when you described it in #256

I feel like "use a config file or the defaults" is too radical.
We have no fallback if there is no config, and it reduces our coverage of use cases.

I understand this for ESLint because there are a lot of rules, but it's manageable for Prettier.

Consider this:

  • Not all teams or projects work with config files (I'm in this situation).
  • The package will not always be used in a project setting: I could hack on a single file without having to define a .prettierrc for example.

"description":
"Use [EditorConfig](http://editorconfig.org/) configuration to load project-based settings for Prettier formatting.<br>Takes precedence over your settings. The following settings will be overriden if they are found in your `.editorconfig`: **Use tabs**, **Tab width**, **Print width**.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should keep this option? At least until prettier/prettier#42 is closed.
It's the third most popular request if you sort issues by 👍 reactions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And then do a reverse merge, like if it's in the prettier config's options, use that, if not, use the editor config's options?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, basically keep it as a fallback for people who don't use config files.

@robwise
Copy link
Collaborator Author

robwise commented Sep 5, 2017

@darahak So you think:

keep:

  • formatting options
  • editorconfig inference

remove:

  • blacklist globs
  • whitelist globs
  • ability to not format on save if prettier is not installed locally
  • parser-specific scopes (or maybe we still need this? — will investigate)

@darahak
Copy link
Collaborator

darahak commented Sep 5, 2017

@robwise Yes, basically keep formatting options because they are still a good interface for CLI single options, and EditorConfig support because Prettier Config is not a complete replacement IMO (see prettier/prettier#42 for related discussion).

I'm not sure about these two:

  • ability to not format on save if prettier is not installed locally
  • parser-specific scopes (or maybe we still need this? — will investigate)

In the end, it's just my opinion. It would be great to have some feedback from users.
Maybe do a beta or a pre-release?

@darahak
Copy link
Collaborator

darahak commented Sep 5, 2017

On second thought, would it be a good idea to add an option that says: only use Prettier Config or default options (current proposal)?

If it's disabled, the package is able to fall back on user settings.

@darahak
Copy link
Collaborator

darahak commented Sep 6, 2017

Current PR for EditorConfig support: prettier/prettier#2760

@robwise
Copy link
Collaborator Author

robwise commented Sep 8, 2017

Just an update, still working on this, but I have to wait until Prettier releases resolveConfig.sync as otherwise Atom's save doesn't get blocked and we format too late in some cases (also needs the release from prettier-eslint that reverts back to synchronous as well: prettier/prettier-eslint#123)

@codecov-io
Copy link

codecov-io commented Sep 13, 2017

Codecov Report

Merging #261 into master will increase coverage by 1.51%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #261      +/-   ##
=========================================
+ Coverage   76.29%   77.8%   +1.51%     
=========================================
  Files          26      29       +3     
  Lines         426     455      +29     
  Branches       40      44       +4     
=========================================
+ Hits          325     354      +29     
  Misses         87      87              
  Partials       14      14
Impacted Files Coverage Δ
src/atomInterface/index.js 91.11% <100%> (+0.2%) ⬆️
src/helpers/atomRelated.js 100% <100%> (ø)
...rc/executePrettier/executePrettierOnBufferRange.js 100% <100%> (ø) ⬆️
src/helpers/index.js 100% <100%> (ø) ⬆️
src/formatOnSave/isFilePathPrettierIgnored.js 100% <100%> (ø)
src/executePrettier/buildPrettierOptions.js 100% <100%> (ø) ⬆️
src/helpers/general.js 100% <100%> (ø)
src/formatOnSave/shouldFormatOnSave.js 100% <100%> (ø) ⬆️
src/helpers/getPrettierInstance.js 100% <100%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cac91ab...2d68a4e. Read the comment docs.

@azz
Copy link
Member

azz commented Sep 14, 2017

Tracking for 1.6.2 which will include .sync() prettier/prettier#2804

@robwise robwise force-pushed the rob/prettier-config branch 2 times, most recently from 9d0b326 to 0c07a43 Compare September 15, 2017 01:19
@robwise robwise changed the title [WIP] Implement Prettier Config Implement Prettier Config Sep 15, 2017
@robwise robwise merged commit 46f32fb into master Sep 15, 2017
@robwise robwise deleted the rob/prettier-config branch September 15, 2017 01:34
@robwise robwise mentioned this pull request Mar 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants