-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Change default of singleQuote to true #7466
Changes from 14 commits
f2ee3d2
a71d126
e858673
8ba5d74
8f2fd39
6d18a88
58eb66f
d0647dc
e3a16f5
66284c0
39cd51c
85e54ed
d7cd2d6
c1fd013
5d2304c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#### Change default value for `singleQuotes` to `true` ([#7466](https://github.com/prettier/prettier/pull/7466) by [@karlhorky](https://github.com/karlhorky)) | ||
|
||
[Since version 0.0.1](https://github.com/prettier/prettier/commit/599b4311bb6be9204689a7725d37d6fdfca770aa), Prettier has an [option](https://prettier.io/docs/en/options.html#quotes) to use single quotes instead of double quotes. | ||
Since version 2.0, the default of this option changes from `false` to `true`. | ||
|
||
<!-- prettier-ignore --> | ||
```js | ||
// Input | ||
const foo = 'bar'; | ||
// Prettier stable | ||
const foo = "bar"; | ||
// Prettier master | ||
const foo = 'bar'; | ||
``` | ||
|
||
The JavaScript ecosystem has largely standardized on single quotes, with it being the most popular style seen in the wild. | ||
|
||
If the old behavior is still preferred, please configure Prettier with `{ "singleQuotes": false }`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ The first requirement of Prettier is to output valid code that has the exact sam | |
|
||
### Strings | ||
|
||
Double or single quotes? Prettier chooses the one which results in the fewest number of escapes. `"It's gettin' better!"`, not `'It\'s gettin\' better!'`. In case of a tie, Prettier defaults to double quotes (but that can be changed via the [`--single-quote`](options.html#quotes) option). | ||
Double or single quotes? Prettier formats to the one which results in a fewest number of escapes. `'We call it "Prettier".'`, not `"We call it \"Prettier\"."`. In case of a tie, Prettier defaults to single quotes (but that can be changed via the [`--single-quote`](options.html#quotes) option). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, fixed! This was an artifact from a previous wording that I changed back (but not completely!). |
||
|
||
JSX has its own option for quotes: [`--jsx-single-quote`](options.html#jsx-quotes). | ||
JSX takes its roots from HTML, where the dominant use of quotes for attributes is double quotes. Browser developer tools also follow this convention by always displaying HTML with double quotes, even if the source code uses single quotes. A separate option allows using single quotes for JS and double quotes for "HTML" (JSX). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
People are going to ask for sources on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, interesting perspective - I think they won't. I think that most JavaScript developers have already had this experience of single quotes being the norm by trolling through documentation and examples from all over the place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's not about your opinion or my opinion, so maybe we can get some statistics together on this!
Some sources:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will ask for some help in #4102.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I write JS every day, and I honestly have no clue what’s the norm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will continue my research (and get some other people to help too). Single quotes are almost everywhere, so collecting them isn't tough to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Microsoft is really the only counter-example I can think of. They use doubled quotes.
The typescript source code: https://github.com/microsoft/TypeScript/blob/master/src/tsserver/server.ts
The typescript documentation: https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@styfle Thanks! I've added this to the list:
#4102 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karlhorky Maybe you could move the content of that comment into the original post because github auto-collapses comments in the middle so its unlikely someone will see that who is just finding this PR (like myself).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I moved it yesterday already actually, under the link text "my review of the ecosystem"