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

Change the default value for singleQuote to true #4102

Open
lipis opened this issue Mar 5, 2018 · 147 comments
Open

Change the default value for singleQuote to true #4102

lipis opened this issue Mar 5, 2018 · 147 comments
Labels
status:needs discussion Issues needing discussion and a decision to be made before action can be taken
Milestone

Comments

@lipis
Copy link
Member

lipis commented Mar 5, 2018

From #3503 (comment)

@lipis lipis added the status:needs discussion Issues needing discussion and a decision to be made before action can be taken label Mar 5, 2018
@lipis lipis added this to the 2.0 milestone Mar 5, 2018
@mvolkmann
Copy link

Every JavaScript survey I've ever seen shows that most developers prefer single quotes for literal strings.

@yvele
Copy link

yvele commented Mar 28, 2018

Most of popular languages (go, C#, java, C, C++, rust) strictly uses double quotes, why should there be an exception? 🤔 (python uses both)

Other languages

Language Double quotes Single quotes
go Yes
Python Yes Yes
C# Yes
java Yes
C Yes
C++ Yes
rust Yes
Lua Yes Yes

Other code formatters

Name Language Quotes
Black Python Double quotes (discussion)

Document languages

Language Double quotes Single quotes
CSS Yes Yes
HTML Yes Yes

Data related languages

Language Double quotes Single quotes
JSON Yes
YAML Yes Yes
GraphQL Yes
XML Yes

JavaScript related Guidelines

Guidelines Quotes
Airbnb Single quotes
Google Single quotes
React Single quotes but Double quotes for JSX properties
TypeScript Double quotes (for Contributors)
Vues.js Don't mind
jQuery Double quotes
Node.js Single quotes (for Contributors)
Deno Double quotes

Console

See also how console outputs

Console Quotes
Chrome Double quotes
Firefox Double quotes
Edge/IE Double quotes
Safari Double quotes
Node.js Single quotes
Deno Double quotes

@j-f1
Copy link
Member

j-f1 commented Mar 28, 2018

Because single quotes are less noisy.

@lipis
Copy link
Member Author

lipis commented Mar 28, 2018

At least 50% less noisy :)

@alo
Copy link

alo commented Apr 3, 2018

This is from the Google JavaScript Style Guide

Use single quotes

Ordinary string literals are delimited with single quotes ('), rather than double quotes (").

@a118n
Copy link

a118n commented Apr 3, 2018

Both Airbnb and Google style guides use single quotes. Switching this to default would be quite sensible, since a lot of companies/devs use their guides.

@craigmorrison
Copy link

craigmorrison commented Apr 3, 2018

A large reason for single quotes being common in JS compared to other langauges is that it reads well when quoting HTML and some selectors.

For example:

document.querySelector('[data-foo="bar"]')

The alternatives are to:

  • escape the quotes, which is harder to read
  • use single quotes with HTML, which is stranger to most people than using them in JS
  • use template strings but there is still a lot of ES5 being written

@yvele
Copy link

yvele commented Apr 3, 2018

@a118n alright I've updated my post with those informations 😉

@TakahiRoyte
Copy link

In addition to @craigmorrison 's comment, big JavaScript frameworks, such as Angular and Vue, often contains JavaScript implementation inside HTLM attributes.

// Vue example
<button @click="submit('string value')">Submit</button>

// Angular example
<button (click)="service.submit('string value')">Submit</button>

For such a case single quotes must be used in order to avoid interference with HTML's double quotation. The important part is how JavaScript is used, not what other languages use.

I strongly recommend single quotes to be used.

@kachkaev
Copy link
Member

kachkaev commented Apr 20, 2018

Prettier supports plugins for python, php, swift, elm, java, pg, ruby, etc. Most of the languages use double quotes (see comment above), so won't a switch cause more harm and ambiguity than benefits?

I agree that single quotes are 50% less noisy and was preferring them for a couple of years after looking at the airbnb style guide. I now use double quotes in JS and TS files again simply because that's Prettier's default and can't say it's terrible. On a positive side, the quotes are the same in JS and JSON, which simplifies string search (e.g. package names).

Airbnb and Google style guides are JavaScript-only, while Prettier is slowly becoming a cross-language tool. IMO this needs to be taken into account when making the final decision for 2.0. And, of course, the diffs that zero-config users would have is also something worth thinking about.

@brocoli
Copy link

brocoli commented May 7, 2018

There's also the "avoidEscape" setting in eslint, which is pretty useful for readability, be it with single or double quotes.

@j-f1
Copy link
Member

j-f1 commented May 7, 2018

That’s already what we do @brocoli and I agree that it’s helpful.

@lydell
Copy link
Member

lydell commented May 30, 2018

The new Python formatter "black" uses double quotes: https://github.com/ambv/black/#strings. Discussion: psf/black#118

@j-f1
Copy link
Member

j-f1 commented Jun 10, 2018

@iamclaytonray Don’t worry — we’d never intentionality break your code. If the language only supports double quotes, we’ll print double quotes. Since Prettier isn’t a general formatter (we need to manually add support for each new language), there shouldn’t be issues with quotes being changed illegally.

karlhorky added a commit to karlhorky/dotfiles that referenced this issue Oct 1, 2018
Will be default in future Prettier version.

Ref: prettier/prettier#4102
@dandonahoe
Copy link

So is there a way to override the double quote default? I'm tearing my hair out trying to get this working. It totally breaks all of our style rules.

@mvolkmann
Copy link

@dandonahoe
Copy link

dandonahoe commented Mar 7, 2019

@mvolkmann Thanks for the quick response. I've been toying with that but I'm not seeing it work. Here's my setup, with the ugly red circles being points of configuration. All packages are up to date and listed at the bottom. If you could take a look, I'd really appreciate it. Anything look funky here?

screen shot 2019-03-06 at 7 29 07 pm

"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"prettier": "1.14.3",
"tslint-config-prettier": "^1.18.0"

@hawkrives
Copy link
Contributor

@dandonahoe Could you open a new issue for your problem? Ideally with a reproduction on the playground (https://prettier.io)

@mvolkmann
Copy link

@dandonahoe I've never seen the approach you are using where reading your .prettierrc file inside your .eslintrc file. I thought it was enough for the .prettierrc file to be present.

I have a pretty detailed description of the way I configure ESLint and Prettier at https://github.com/mvolkmann/talks/blob/master/eslint-prettier-2019.key.pdf. Maybe that will help.

@dandonahoe
Copy link

@mvolkmann That approach is meant to solve two use cases.

1 - Allow the IDE to read the .prettierrc
2 - I have a pre-commit git hook that lints staged files, but that only reads the .eslintrc.js, so sucking in the .prettierrc means I only have to add prettier rules in one spot.

Not my idea, but based off this boilerplate: https://github.com/react-boilerplate/react-boilerplate

@mvolkmann
Copy link

mvolkmann commented Mar 7, 2019 via email

@dandonahoe
Copy link

@mvolkmann I use VS Code as well, but as you mentioned, I'll open a separate issue so I don't pollute this one. Thanks again.

@tkrotoff
Copy link

airbnb/javascript#269 (comment):

Holding down the shift key every time you want a string kinda stinks. Your carpal tunnel will thank you for using single quotes.

@paleite
Copy link

paleite commented Aug 9, 2022

On the homepage, the very first section says the following:
image

@JounQin

This is not quite correct because we can be editing without prettier available.

You can't really argue that prettier should want to care how projects without prettier are edited.

Imagine you're editing a PR on the web UI, or editing a file on mobile.

You're arguing on the exception, not the rule. The majority of people will be working in their regular setup most of the time, and not in an extreme setting as the ones you mentioned

How is it automatically corrected to double quotes? Editor/IDE? It is out of scope of prettier IMO, and we can be editing without prettier available as I mentioned above.

On the homepage, that's exactly the scope of prettier. It literally says "You press save and code is formatted" and "Integrates with most editors".

I didn't see anywhere it is announced.

Again, on the homepage it says exactly that: "An opinionated code formatter"

Easier for typing means you can get less conflict style when working on a project using prettier, but you have no prettier available temporarily.

Again, you're arguing on the exception, not the rule, so this is not a use-case that should concern prettier.

@JounQin
Copy link
Member

JounQin commented Aug 9, 2022

VSCode and Prettier can be run on the web, and if you're not using Prettier its settings wouldn't matter to you anyway.

I'm talking about clicking the edit button on GitHub UI without VSCode web.


I agree with @paleite that my concerns are exceptions, but I still disagree that it cannot be discussed for easier accessibility. But at the same time, I think it is OK to ignore this part for rarely scenes.


For my two cents, my conclusion would be:

  1. single quotes are used more commonly in JavaScript world
  2. double quotes are easier for reading for accessibility (while single quotes are easier to type)

The first conclusion makes more sense to me, personally, I'm sorry. Because I want to benefit the most users, we can't make all users be happy, so the most should take higher priority.

I understand many would argument that the accessibility should take higher priority, considering eggs and stones. That's great.


Generally, I'm against to change any default value which has been used for a long time, because it could affect a lot of users.

That's being said, I've just gave up. I'm fine with both.

@phpnode
Copy link
Contributor

phpnode commented Aug 9, 2022

given that prettier has been prevalent for several years, and that the default has been double quotes for all that time, is it even correct to say that single quotes are most used now? We should just leave the defaults as is.

@JounQin
Copy link
Member

JounQin commented Aug 9, 2022

given that prettier has been prevalent for several years, and that the default has been double quotes for all that time, is it even correct to say that single quotes are most used now? We should just leave the defaults as is.

See https://github.com/search?q=singleQuote%3A+true&type=code

@ljharb
Copy link

ljharb commented Aug 9, 2022

Yes, it is quite correct that single quotes are the most common default for JavaScript.

However i explicitly asked for a11y arguments, not inertia arguments :-) the “edit on github.com” concern is an a11y issue, but one that applies to prettier itself and is thus irrelevant for individual prettier configuration values, so there is no value from discussing it.

@nickmccurdy
Copy link
Member

nickmccurdy commented Aug 23, 2022

Here's another reason double quotes are more accessible:

I also prefer to use "" for strings not '', partly because "quote" takes less time to say (compared to "apostrophe", but also because an apostrophe at the end of a string is sometimes (quite correctly) interpreted by the TTS as the plural possessive.
https://twitter.com/LeonieWatson/status/1551238171601543171

If Prettier changed the default to single quotes, using a screenreader would take longer, and formatting would have to be conditional (not formatting strings at the end of lines) to avoid pronunciation issues.

I also think it's worth mentioning that in Java (the language JavaScript's name and syntax are based), all strings (distinct from chars) must be double quoted. Using the same semantics as other languages improves accessibility by reducing cognitive load.

@ljharb
Copy link

ljharb commented Aug 23, 2022

To be clear, Java is not the sole language on which JS's syntax is based, that was a marketing choice - it's based on a number of languages, including Java, Smalltalk, Prolog, and C++, from what I understand. Either way, JS's idioms should never be determined by a different language, as JS has quite surpassed all of them.

@nickmccurdy
Copy link
Member

nickmccurdy commented Aug 23, 2022

Yes, but I still believe that it was meant to appeal to Java developers syntactically. I don't think ES6 would have standardized classes if it wasn't for Java devs being confused by prototypical inheritance.

Anyway, regardless of those idioms, I still have several arguments in favor of double quotes being more accessible, and I haven't seen any counterexamples yet.

@ljharb
Copy link

ljharb commented Aug 23, 2022

@nickmccurdy besides your own assertions, the tweet link is the only source i've seen - can you share the other sources?

@nickmccurdy
Copy link
Member

nickmccurdy commented Aug 23, 2022

Sure.

I personally have cognitive disabilities, which is why I mentioned them when describing the use case of preferring consistent quotes [looking for a cogsci source on this related to cognitive load]. There's also a vision argument to be made there, but that's not one I personally have experience with, so I'll let someone else chime in on that.

Here are several citations showing that the sticky keys feature (for example) makes it easier to type with physical disabilities by having users press less keys:

@paleite
Copy link

paleite commented Aug 23, 2022 via email

@ljharb
Copy link

ljharb commented Aug 23, 2022

@paleite because JS isn't a new language. Its idioms already exist.

@nickmccurdy given that typing an apostrophe would have prettier autocorrect it to a double quote, it seems like "issues with typing" isn't much of a motivation?

@phpnode
Copy link
Contributor

phpnode commented Aug 23, 2022

Yes, it is quite correct that single quotes are the most common default for JavaScript.

This was a bit of a dismissive response, what's your source for this claim?

@ljharb
Copy link

ljharb commented Aug 23, 2022

@phpnode given that http://sideeffect.kr/popularconvention/#javascript has single quotes as more common in 2014, and the airbnb config/guide has always pushed single quotes, and remains the most popular style guide for JS (certainly before prettier, altho it's hard to tell now because prettier is used for many things beyond just JS), I think it would take some pretty compelling data to be persuasive that my claim is not the case.

@phpnode
Copy link
Contributor

phpnode commented Aug 23, 2022

I think you'd have been right historically, but prettier is downloaded 23m times a week now, compared to airbnb's eslint rules at 3m times a week. I'd bet that less than 20% of those prettier consumers have configured single quotes. But without data all we have is reckons.

@nickmccurdy
Copy link
Member

nickmccurdy commented Aug 24, 2022

@nickmccurdy given that typing an apostrophe would have prettier autocorrect it to a double quote, it seems like "issues with typing" isn't much of a motivation?

Prettier generally doesn't format on type. Even if it did, it wouldn't necessarily stop a screenreader from speaking "apostrophe" before it's written to the disk.

@ljharb
Copy link

ljharb commented Aug 24, 2022

Sure, on save. But fair point on the screenreader.

@ghost
Copy link

ghost commented Oct 27, 2022

Is it still possible to land this change in the v3 release? This issue is part of the 3.0 milestone, but several of the remaining issues haven't seen any recent activity despite new alphas being released.

Highlighting a few points (some related to previous comments) in no particular order.

Accessibility isn't going to move the needle in either direction.

First, there are a lot of different assistive technologies and software out there; many are not consistent in how they handle certain cases and many have a lot of user configurable settings. While it's certainly possible that some screen readers might read something like "apostrophe" instead of "quote", it's going to be highly dependent on device, language, specific software, etc.

Second, in one of the tweet quotes above used as a justification, the very next sentence from the original author stated:

These are all personal preferences though, definitely not "this is how assistive tech coders generally do it".

It's going to be nearly impossible to quantify single quotes being materially better or worse than double quotes when it comes to accessibility. This isn't to say accessibility isn't important, but rather, for every source claiming it's better, another source can be found to contradict it, and in many cases, each user has their own preferences and configurations that make most of these discussions moot.

Single quotes are generally preferred across the JS ecosystem for stylistic and pragmatic reasons.

Style guides like AirBnB, Google, StandardJS, the official node docs, previous surveys, and the sheer number of Prettier configs overriding it seem to form a pretty solid basis to support this change.

For more pragmatic reasons, single quotes offer less visual noise and easier ways to write things like query selectors and HTML/JSX attributes, etc. Frameworks like React, Vue, etc. all allow embedding JS inside templates in some form or another, and single quotes can simplify things a lot (plenty of previous comments above going more in depth with examples).

Ultimately, I'm biased as much as anyone else, but this is literally the only thing preventing Prettier from being a completely install and forget it for me. The singleQuote option is the only option I use across every single project, and it would feel amazing to be able to just delete the options block all together and go full vanilla Prettier. 😆

@karlhorky
Copy link
Contributor

karlhorky commented Dec 8, 2022

singleQuote: true default for Prettier v3 🙌 would be amazing to finally have the most common JS/TS style as default, since Prettier is primarily a JS/TS tool. Still more upvotes than downvotes from the community on this (181 👍 vs 62 👎). And to the "too much churn! existing users will need to add config!" arguments we have seen before, think about new developers who don't understand why Prettier always changes their code to something that looks different than the article that they are following (I see situations like this coming from teaching beginners for years now) - it's way harder for them as new developers and (IMO) more user-hostile there.

What do you think @JounQin @j-f1 @lipis @Shinigami92 @lydell @kachkaev @fisker @sosukesuzuki @thorn0 @duailibe ? Possible to give this one another vote from maintainers? We tried and failed for v2, but maybe v3 will show a different outcome.

ChatGPT also thinks single quotes are most common across JS/TS ecosystem 😂 (of course, there's much more proof in the thread above as well, as well as developer surveys, etc)

Screenshot 2022-12-08 at 12 56 59

@phpnode
Copy link
Contributor

phpnode commented Dec 8, 2022

Repeating an argument against making this change which is even more valid now than it was back then given prettier's continued growth:

Changing the defaults to singleQuote: true means that the majority of people who've relied on prettier working out of the box with no configuration will have to accept the new defaults or figure out how to configure prettier to preserve the old behaviour. Billions of lines of code will churn for literally no reason other than because a few opinionated people on github lobbied for this change. It's user-hostile behaviour which shows complete disregard for other people's time and energy, for nothing other than a preference. This is the textbook definition of bikeshedding and getting rid of this kind of silly discussion was a major motivating factor in prettier's initial conception.

@karlhorky
Copy link
Contributor

karlhorky commented Dec 8, 2022

I think there's no need to re-state all arguments from the thread above / start new flame wars - I'm just asking whether we can get a maintainer vote.

It's the responsibility of the maintainers to take all sides of the community feedback into account and decide on the future of Prettier.

@fisker
Copy link
Member

fisker commented Feb 8, 2023

I'm going to postpone this, since we haven't reached a consensus.

@scherii
Copy link

scherii commented Feb 8, 2023

Hi @fisker 🙂
Do you have any thoughts or suggestions on how we can successfully reach consensus?

(Same question for #7475 (comment))

@fisker
Copy link
Member

fisker commented Feb 8, 2023

I think we need implement #2846 first.
Because people prefer different quote style in different languages.

Personally, I do single quote for JS, double quote for HTML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs discussion Issues needing discussion and a decision to be made before action can be taken
Projects
None yet
Development

No branches or pull requests