Add an option to print single quotes in JSX#4798
Add an option to print single quotes in JSX#4798j-f1 merged 8 commits intoprettier:masterfrom smirea:feat-option-singleQuote-jsx
Conversation
suchipi
left a comment
There was a problem hiding this comment.
I really don't think we should add this option... arrow parens I was sympathetic to because it's annoying to eg. convert an identifier to destructuring syntax, and I'm open to space between function name and params list because it makes the code easier to grep. But single/double quotes is just nitpicking, and I don't want the teams that use prettier to have to have a conversation about this.
I know this is unintuitive, since prettier is a code formatter, but in my opinion, the major value of prettier is that it makes you stop caring about syntax. It is not what people expect at first but once you let go it is very freeing to "let the formatting be what it will" and focus on the problems the code is solving instead of the aesthetic of the code.
|
@suchipi thoughts on putting this to a private vote amongst the maintainers or something? Perhaps over email? We're all in agreement that we hate bikeshedding discussions, but it's not clear that there's overwhelming evidence one way or another on this one (eg; community demand seems strong, including from some luminaries). Eg; prettier's existence/stance doesn't seem to prevent teams from having conversations about this, it's just "do we use prettier when it lacks this feature". |
|
I can say that I haven't yet adopted prettier specifically because of its lack of support for single quote JSX attributes. We don't write conversational english in our raw attributes, there is no need to care about the need to handle a potential apostrophe in your text, and forcing the attributes to be double quotes when all your other strings are single quotes is disorienting. But I'm not an influencer I guess. All this discussion was already had in the long issue thread that OP mentioned. |
|
Yeah @Kovensky let's please avoid rehashing conversations 😄, it's clear from #1080 there's strong community demand, and countless reasons have been mentioned in that thread. It's a clear tradeoff between "give the people what they want" and "never add options", which is just up to the maintainers. In any case @smirea thanks for the work on this PR – the better it looks, the more likely it'll be accepted, I hope 🙂 |
|
hi all, bump on this. I think I've addressed all the pending questions in the last commit from a few weeks ago. Can y'all take another look so I can do a final rebase |
|
I still don't think that we should add this, but if we do, for what it's worth, some plugins are relying on singleQuote being boolean; I'm not sure if they can use support info to figure out how they're supposed to handle that. |
|
We should change options to be language-specific, e.g. |
|
this feature is backwards compatible with the old signature via the config. We could support all 5 options (true/js false/none all) without a deprecation to not have it be slightly awkward for non-js projects, my 2 cents is that it's better to bite the bullet sooner rather than later Example of the current behavior: |
|
@smirea I mean like here: https://github.com/prettier/plugin-lua/blob/7e41cece6200de35244e1bea118452cb5efad5fa/src/printer.js#L570 Any prettier plugin could be relying on that option being a boolean. |
|
Any luck on this to be merged if approved? |
|
I have no opinion on this PR but it shouldn't break other plugins #4798 (comment). |
|
@ikatyang - agreed that that's a blocker to merge, though I'm guessing the author of this PR would rather not deal with implementing a solution for that until it's clear we want the change. |
|
I'm happy to fix the blockers if there is a desire to merge this, there's still a significant community desire for this feature :) |
This comment has been minimized.
This comment has been minimized.
- Uses [`vnopts`](https://github.com/ikatyang/vnopts#readme) - This way it should be easier to support language-specific options (#4798 (comment)) and map the common options to language-specific options using [`forward`](https://github.com/ikatyang/vnopts#forward), e.g. `singleQuote: true` -> `"javascript/singleQuote": "js"`, `singleQuote: false` -> `"javascript/singleQuote": "none"`.
|
Quick vote for @prettier/core (only maintainers please): 👍 if this should be merged, 👎 if it shouldn’t. |
|
What about |
|
How about |
|
FYI, we could forward singleQuote to jsSingleQuote to avoid breaking change, see #5020 for more info. |
|
After second thought, it actually can be an independent bool option ( |
|
Personally personally, I would've not even added an extra option and have jsx follow js quotes and not have the notion of "we use a type of quote everywhere in js, except for this place" ... but I get how that is not possible now In lieu of that, I think the I'll give it a day and if there aren't any other suggestions i'll go ahead and add |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Ok I've updated the PR with:
Can y'all have another gander and see if this checks out? |
|
hey all, all comments were addressed and everything is done from my end in the last commit. |
|
@j-f1 since you requested changes before, would you like to do a final review? |
|
Just needs conflicts resolved. |
|
conflicts fixed, snapshots updated, checks passed, we're green across the board! |
|
Thank you for contributing to Prettier! |

Extending the
single-quoteoption to allow using single quotes in JSX.single-quotehas been changed from aboolto a choice:none(false),js(true),all(new functionality, includes JSX)Functionality based on this comment from the long issue thread
Fixes #1080.