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

Re-add EditorConfig support (undo #3213) #3255

Merged
merged 20 commits into from Dec 4, 2017

Conversation

josephfrazier
Copy link
Collaborator

Reintroducing #2760 for the 1.9 release, as suggested in #3213 (comment)

This reverts commit d2241fc.

@josephfrazier josephfrazier added this to the 1.9 milestone Nov 12, 2017
@@ -83,3 +83,13 @@ For more information on how to use the CLI to locate a file, see the [CLI](cli.m
## Configuration Schema

If you'd like a JSON schema to validate your configuration, one is available here: http://json.schemastore.org/prettierrc.

<!--
## EditorConfig
Copy link
Member

Choose a reason for hiding this comment

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

I think we can add an _available in v1.9.0+_ note just like https://prettier.io/docs/en/options.html#prose-wrap, so that we don't have to uncomment new feature every time and it's clearer which version is available for it.

@lipis
Copy link
Member

lipis commented Nov 16, 2017

Will the following work out of the box, just by running Prettier on all supported files?

root = true

[*]
indent_style = space
indent_size = 2
max_line_length = 80

[*.{js,jsx}]
max_line_length = 120

[*.json]
indent_size = 4
max_line_length = 200

@josephfrazier
Copy link
Collaborator Author

@lipis, I think so! If you have a clone of the prettier repo, you can test this branch using hub:

hub checkout https://github.com/prettier/prettier/pull/3255
yarn
./bin/prettier.js /the/globs/of/your/files

@lipis
Copy link
Member

lipis commented Nov 16, 2017

Maybe we should support filetypes inside the .prettierrc somehow.. would be awesome :) Maybe I should create a new issue for that though..

@josephfrazier
Copy link
Collaborator Author

@lipis
Copy link
Member

lipis commented Nov 16, 2017

WHAT?! Nice.. thanks :) RTFM :D

@josephfrazier
Copy link
Collaborator Author

You're welcome! If you do test this branch with the .editorconfig file you posted above, please let me know how it goes.

@lipis
Copy link
Member

lipis commented Nov 16, 2017

I will once I'll get home.. :)

mergeOverrides(Object.assign({}, result), filePath)
);

if (Object.keys(merged).length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look the same as the current behaviour. We want an empty config file to be different than no config file. How this works with .editorconfig... I don't know. Editors want to support formatting only if a config file is found, so supporting EditorConfig might break that functionality.

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 doesn't look the same as the current behaviour.

According to @robwise in #2760 (comment), the current behavior treats missing/empty config files equivalently. I wanted to be sure, so here's a script you can run against a clean build of cbed0f4 to try it out:

tmpdir=`mktemp -d`
tmpfile=$tmpdir/file.js
tmprc=$tmpdir/.prettierrc

echo -n > $tmpfile

echo "With no .prettierrc"
node -p "require('./').resolveConfig.sync('$tmpfile')"
echo

echo "With empty .prettierrc"
echo -n > $tmprc
node -p "require('./').resolveConfig.sync('$tmpfile')"
echo

rm -rf $tmpdir

On my machine, this prints:

With no .prettierrc
null

With empty .prettierrc
null

Because of this, I'd like to fix this missing/empty distinction in a separate PR, since it's pre-existing and (somewhat?) unrelated (see #2760 (comment))

How this works with .editorconfig... I don't know. Editors want to support formatting only if a config file is found, so supporting EditorConfig might break that functionality.

Hmm, I guess the use-case here is:

  • The user has a prettier integration in their editor
  • The integration is configured to format-on-save if a prettier configuration exists
  • The user is working on a project that has a .editorconfig
  • But the project's style guide is incompatible with prettier's formatting

Yeah, I could see how that might get tricky. I'm going to have to give it some more thought.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I could see how that might get tricky. I'm going to have to give it some more thought.

Ok, so one way to fix this is to make it so that resolveConfigFile() (and its CLI counterpart --find-config-path) return paths to empty .prettierrc files (it doesn't currently). Once that's the case, the editor integration can use it to determine whether an empty .prettierrc exists, even if resolveConfig returns an object derived from .editorconfig.

Copy link
Member

Choose a reason for hiding this comment

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

Using resolveConfigFile(path) != null could be a solution.
I've not seen this function exposed for now, seems to be cli only.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, so one way to fix this is to make it so that resolveConfigFile() (and its CLI counterpart --find-config-path) return paths to empty .prettierrc files (it doesn't currently).

Hmm, it looks like cosmiconfig intentionally ignores empty files: cosmiconfig/cosmiconfig@1adf5c2

However, a .prettierrc file containing just a space or a newline is still found, so that could be the suggested workaround instead of this from #2760 (comment):

azz
azz previously requested changes Nov 21, 2017
Copy link
Member

@azz azz left a comment

Choose a reason for hiding this comment

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

⬆️

@lipis
Copy link
Member

lipis commented Nov 27, 2017

Are we there yet?! It works :)

@josephfrazier
Copy link
Collaborator Author

I think there's still a risk that some editor integrations could break under certain circumstances (see #3255 (comment) for details). Besides, we also want to make sure that there are no more patch releases before 1.9.0, so this is kinda just chilling for now.

@duailibe duailibe mentioned this pull request Nov 28, 2017
5 tasks
@josephfrazier
Copy link
Collaborator Author

It sounds like 1.9.0 is going to be the next release (#3333 (comment)). @azz, do you have any thoughts on #3255 (comment)?

@azz
Copy link
Member

azz commented Dec 1, 2017

How about this:

Add a editorconfig: true|false to the options of resolveConfig to disable lookup of editorconfig. Default to false for backwards compat, but set it to true internally from the CLI.

@josephfrazier
Copy link
Collaborator Author

That sounds like a great way to sidestep potential editor integration issues, while still making prettier friendly to new users that use EditorConfig in their projects! I'll see what I can do

@azz
Copy link
Member

azz commented Dec 3, 2017

Looks like this is the last one left in the 1.9 milestone. Did you get a chance to make that change?

@josephfrazier
Copy link
Collaborator Author

It's still in-progress. I think there are a few more things in the milestone, though? https://github.com/prettier/prettier/milestone/7

@azz
Copy link
Member

azz commented Dec 3, 2017

#3379 has since been added. The rest are post release items

@azz azz merged commit cecf065 into prettier:master Dec 4, 2017
@azz
Copy link
Member

azz commented Dec 4, 2017

Sorry this took so long to get in!

@lipis
Copy link
Member

lipis commented Dec 4, 2017

KaBoom! 💥 🎆

@josephfrazier
Copy link
Collaborator Author

🎉 It's understandable, @azz. This turned out to be a tricky change to get right. I'll see if I can add a little more detail to the release draft.

josephfrazier added a commit to josephfrazier/prettier that referenced this pull request Feb 17, 2018
azz pushed a commit that referenced this pull request Feb 24, 2018
* Respect EditorConfig when `--config` is passed

* Clarify config-resolution test file

See #3255 (comment)

* Update test snapshots
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
@josephfrazier josephfrazier deleted the editorconfig-2 branch January 2, 2020 00:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants