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
Consider removing default parser / Skip processing unsupported file types #2884
Comments
I like the idea! (It might be worth thinking about #2846 at the same time, or even re-thinking the CLI overall. It is quite messy. At the same time we shouldn't cause unnecessary backwards incompatibility. So it might also be better to not mix anything else into the thought process of this issue. I don't know.) |
Couldn't this be done without a breaking change? Prettier's parsing of incompatible files generally errors anyway, I don't think a noop would hurt anyone's workflow as those files would already not be formatted properly by Prettier. I do like the idea of #2846 but it seems like it could be done after. |
I consider this behavior a bug, not a feature, and by that logic, I think we should make this change without waiting for 2.0. |
I think it's really important that we figure out a non-breaking way that fixes 80% of the cases as soon as possible, because lots of users are confused when Prettier tries to format HTML files, which sometimes succeeds and sometimes doesn't, depending on if the HTML is valid JSX or not. Could this work out, maybe? If Prettier is told to format a file with an extension it does not recognize and the We have to be really careful so we don't break editor integrations that rely on the CLI such as vim-prettier (ping @mitermayer) though. I also think we can consider this a bug and not wait for 2.0. |
@lydell could this be implemented as built-in an HTML plugin, which simply does not do anything? I.e. it'll parse the entire text into a syntax tree with a single node and simply print it back as is. |
@kachkaev That's a really clever solution if my proposal doesn't work out 👍 |
Making A dummy plugin for HTML files will require minimal changes to the architecture of Prettier and will be a right step towards properly implementing it one day. It will also save people from the confusion you are mentioning. |
I didn't mean that we should special-case HTML. This would be the warning message template: |
Where would that message go? Stderr? Will |
Most likely, yes.
That was my idea, yes.If so, that sounds like a v2 behaviour to me, which is right, but breaking.
Why? |
Because currently Prettier swallows files with all extensions and if a parser cannot be determined, it uses a fallback babel parser. That's not ideal, yes, but that's how things are at the moment. Downstream projects like editor extensions can be using this 'feature' in ways we don't know, so if we want to change the behaviour, it can be only done in Prettier 2.0 (which would allow for breaking changes). Because Prettier adheres semantic versioning and this gives certain promises to the community, there are limitations to what can be changed within a single major version (currently v1). |
So let's ask them.
Then we're doomed :) Or we have to make a really boring 2.0 with only this change. |
Fwiw, prettier doesn’t really adhere to semantic versioning, at every release, including patch ones, the output of some code will change, so it’s a breaking change as you’ll need to run it through your codebase to get you unblocked. |
Let's just ask the most popular ones.
The question is: If |
It wouldn't be a problem for prettier-emacs. The users could conditionally add specific |
Hi! I'm the developer who wrote most of the code for the WebStorm integration. |
@undeadcat thanks so much for building it, it’s been a highly requested from people using prettier! |
FTR I wrote https://github.com/duailibe/atom-miniprettier and it doesn't try to infer a parser at all, defers that completely to Prettier. It's been working great so far! :) With this behavior, I won't have to change anything since that's exactly the behavior I want 😄 |
@duailibe so will your plugin try to prettify any file extension using babel parser as a fallback now? We try to avoid this with @robwise in #4341 to make prettier-atom lighter (prettier/prettier-atom#404). |
@kachkaev for now, yes. But since I don't use autosave, that's not an actual problem for me. I'm just commenting on that thread right now. :) |
I opened a PR that implements this change, I need some help implementing the error message that @lydell mentioned in #2884 (comment), but otherwise it is functional |
In the same vein, @mitermayer @rocedo @undeadcat @madskristensen we are thinking about changing the JavaScript API to require passing either > prettier.format("function bla () {}")
'function bla () {}'
> prettier.format("function bla () {}", { filepath: "foo.js" })
'function bla() {}\n'
> prettier.format("function bla () {}", { parser: "babylon" })
'function bla() {}\n' This will affect Would this adversely affect you? Are you always specifying either parser or filepath? Context: #4426 (comment) |
cc @rcoedo since your username wasn’t highlighted in the above comment. |
Thanks @j-f1 |
We don't use the JS API in the emacs package 👍 |
The WebStorm plugin always passes |
cc @robwise |
prettier-atom does not always pass filepath (in cases where the user has chosen to manually format text in a draft document that has not yet been saved as a file). Currently, we specify the parser, but that's about to change with #4341 where we will rely on Prettier to tell us what parser to use. |
In |
@suchipi sorry for late response. Currently, we always specify a parser based on Atom scope, but after #4341 we just don't pass a parser or filepath at all if the file is not saved and prettier reverts to a JS parser and attempts to format with that. I would stay away from prettier supporting editor scope, that would quickly turn into a nightmare to support. IMO it really should be the editor integration's responsibility if we wanted to go that route, but we're purposely deleting all of the code doing this in #4341 because that paradigm makes it basically impossible to support the new prettier plugins feature. |
@suchipi I think we're safe to go forward with this |
Ok, cool |
Currently when
--parser
option is passed, andparser
is in a prettier config file,then it will fall back to the babylon parser and treat the file as JavaScript. This made sense when prettier only supported JS (and then TypeScript), but now that it supports vastly different languages perhaps it is time to challenge that default.
In #2882, we discovered this can have negative repercussions when used with
--write **/*
, modifying files inside of a.git
directory.If we were to change the default from JavaScript to a no-op, these kind of issues would go away, and we'd also have less issues reported along the lines of "My CSS doesn't parse", when they're accidentally using the babylon parser.
It is already possible to associate other extensions with a parser in
.prettierrc
.Thoughts @lydell @vjeux?
The text was updated successfully, but these errors were encountered: