Skip to content

Add an option to print single quotes in JSX#4798

Merged
j-f1 merged 8 commits intoprettier:masterfrom
smirea:feat-option-singleQuote-jsx
Nov 4, 2018
Merged

Add an option to print single quotes in JSX#4798
j-f1 merged 8 commits intoprettier:masterfrom
smirea:feat-option-singleQuote-jsx

Conversation

@smirea
Copy link
Copy Markdown
Contributor

@smirea smirea commented Jul 3, 2018

Extending the single-quote option to allow using single quotes in JSX.
single-quote has been changed from a bool to a choice: none (false), js (true), all (new functionality, includes JSX)

Functionality based on this comment from the long issue thread

Fixes #1080.

Comment thread src/language-js/printer-estree.js Outdated
Comment thread src/language-js/printer-estree.js Outdated
@smirea smirea changed the title Feat option single quote jsx Feat option single quote jsx, fixes #1080 Jul 3, 2018
Comment thread src/language-js/printer-estree.js Outdated
Copy link
Copy Markdown
Member

@suchipi suchipi left a comment

Choose a reason for hiding this comment

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

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.

@rattrayalex
Copy link
Copy Markdown
Collaborator

@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".

@Jessidhia
Copy link
Copy Markdown

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.

Comment thread src/language-js/printer-estree.js Outdated
@rattrayalex
Copy link
Copy Markdown
Collaborator

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 🙂

Comment thread src/language-js/printer-estree.js Outdated
@smirea
Copy link
Copy Markdown
Contributor Author

smirea commented Jul 23, 2018

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

@suchipi
Copy link
Copy Markdown
Member

suchipi commented Jul 23, 2018

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.

@ikatyang
Copy link
Copy Markdown
Member

We should change options to be language-specific, e.g. "javascript/singleQuote": "something", though not sure how should it work.

@smirea
Copy link
Copy Markdown
Contributor Author

smirea commented Jul 24, 2018

this feature is backwards compatible with the old signature via the config.
right now singleQuote: true redirects to singleQuote: js and false converts to none with an accompanying deprecation warning, so old modules will still work.

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:

screen shot 2018-07-24 at 9 48 02 am

@suchipi
Copy link
Copy Markdown
Member

suchipi commented Jul 24, 2018

@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.

@bovas85
Copy link
Copy Markdown

bovas85 commented Aug 12, 2018

Any luck on this to be merged if approved?

@rattrayalex
Copy link
Copy Markdown
Collaborator

rattrayalex commented Aug 17, 2018

Quick 👍 / 👎 – maintainers only please – @j-f1 @suchipi @lydell @ikatyang @vjeux @jlongster @azz (and any other maintainers who are watching) – should we merge this?

@ikatyang
Copy link
Copy Markdown
Member

I have no opinion on this PR but it shouldn't break other plugins #4798 (comment).

@rattrayalex
Copy link
Copy Markdown
Collaborator

@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.

@smirea
Copy link
Copy Markdown
Contributor Author

smirea commented Aug 17, 2018

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 :)

@bovas85

This comment has been minimized.

@j-f1 j-f1 changed the title Feat option single quote jsx, fixes #1080 Add an option to print single quotes in JSX Aug 18, 2018
ikatyang added a commit that referenced this pull request Aug 31, 2018
- 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"`.
@j-f1
Copy link
Copy Markdown
Member

j-f1 commented Sep 27, 2018

Quick vote for @prettier/core (only maintainers please): 👍 if this should be merged, 👎 if it shouldn’t.

@lydell
Copy link
Copy Markdown
Member

lydell commented Sep 27, 2018

What about always, never, except-jsx as the option values?

@j-f1
Copy link
Copy Markdown
Member

j-f1 commented Sep 27, 2018

How about false, true, and @lydell’s "except-jsx"? This would mean that falsy values mean double quotes and truthy values single quotes, and the JS parser would look more closely at the exact values.

@ikatyang
Copy link
Copy Markdown
Member

FYI, we could forward singleQuote to jsSingleQuote to avoid breaking change, see #5020 for more info.

@ikatyang
Copy link
Copy Markdown
Member

After second thought, it actually can be an independent bool option (--jsx-single-quote), there's no need to forward them (unnecessary complexity). What do you think?

@smirea
Copy link
Copy Markdown
Contributor Author

smirea commented Oct 28, 2018

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 --jsx-single-quote actually makes the most sense, it did feel a bit weird having an option override another

I'll give it a day and if there aren't any other suggestions i'll go ahead and add --jsx-single-quote and wrap it up

@j-f1

This comment has been minimized.

@lydell

This comment has been minimized.

@smirea
Copy link
Copy Markdown
Contributor Author

smirea commented Oct 29, 2018

Ok I've updated the PR with:

  • use jsx-single-quote plain ol' boolean, removed all the vnopts magic
  • updated docs
  • updated snapshots

Can y'all have another gander and see if this checks out?

Comment thread docs/options.md Outdated
Comment thread docs/options.md Outdated
Comment thread docs/options.md Outdated
Comment thread tests/markdown/__snapshots__/jsfmt.spec.js.snap Outdated
Comment thread tests/quotes/jsfmt.spec.js Outdated
@smirea
Copy link
Copy Markdown
Contributor Author

smirea commented Nov 1, 2018

hey all, all comments were addressed and everything is done from my end in the last commit.
Any final thoughts? If not, could we look into actually merging this finally? 😄

Comment thread src/common/util.js Outdated
@ikatyang
Copy link
Copy Markdown
Member

ikatyang commented Nov 4, 2018

@j-f1 since you requested changes before, would you like to do a final review?

@ikatyang ikatyang added this to the 1.15 milestone Nov 4, 2018
ikatyang added a commit to ikatyang/prettier that referenced this pull request Nov 4, 2018
Copy link
Copy Markdown
Member

@j-f1 j-f1 left a comment

Choose a reason for hiding this comment

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

:shipit: 🚢 🚀

@j-f1
Copy link
Copy Markdown
Member

j-f1 commented Nov 4, 2018

Just needs conflicts resolved.

@smirea
Copy link
Copy Markdown
Contributor Author

smirea commented Nov 4, 2018

conflicts fixed, snapshots updated, checks passed, we're green across the board!

@j-f1 j-f1 merged commit e17512a into prettier:master Nov 4, 2018
@j-f1
Copy link
Copy Markdown
Member

j-f1 commented Nov 4, 2018

Thank you for contributing to Prettier!

@smirea smirea deleted the feat-option-singleQuote-jsx branch November 4, 2018 21:48
@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Feb 2, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Feb 2, 2019
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.

10 participants