-
-
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 the default value for singleQuote to true #4102
Comments
Every JavaScript survey I've ever seen shows that most developers prefer single quotes for literal strings. |
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
Other code formatters
Document languages
Data related languages
JavaScript related Guidelines
ConsoleSee also how console outputs
|
Because single quotes are less noisy. |
At least 50% less noisy :) |
This is from the Google JavaScript Style Guide Use single quotes
|
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. |
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:
|
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. |
Prettier supports plugins for 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. |
There's also the "avoidEscape" setting in eslint, which is pretty useful for readability, be it with single or double quotes. |
That’s already what we do @brocoli and I agree that it’s helpful. |
The new Python formatter "black" uses double quotes: https://github.com/ambv/black/#strings. Discussion: psf/black#118 |
@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. |
Will be default in future Prettier version. Ref: prettier/prettier#4102
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 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? "eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"prettier": "1.14.3",
"tslint-config-prettier": "^1.18.0" |
@dandonahoe Could you open a new issue for your problem? Ideally with a reproduction on the playground (https://prettier.io) |
@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. |
@mvolkmann That approach is meant to solve two use cases. 1 - Allow the IDE to read the Not my idea, but based off this boilerplate: https://github.com/react-boilerplate/react-boilerplate |
I wonder why the IDE can't get the Prettier settings from .prettierrc. I
use VS Code and it does that.
…On Thu, Mar 7, 2019 at 8:14 AM Dan Donahoe ***@***.***> wrote:
@mvolkmann <https://github.com/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
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4102 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAE10MqdDBf63hSqBtq7ovPS84Xljqa9ks5vUR6ugaJpZM4ScMrl>
.
--
R. Mark Volkmann
Object Computing, Inc.
|
@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. |
airbnb/javascript#269 (comment):
|
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 For my two cents, my conclusion would be:
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 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. |
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 |
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. |
Here's another reason double quotes are more accessible:
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. |
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. |
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. |
@nickmccurdy besides your own assertions, the tweet link is the only source i've seen - can you share the other sources? |
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:
|
I’m curious, why should it never be determined by a different language? Is
it always a bad idea to adopt idioms because they’re already established in
a different language?
…On Tue, 23 Aug 2022 at 08:13 Jordan Harband ***@***.***> wrote:
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.
—
Reply to this email directly, view it on GitHub
<#4102 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABBZVQDNX6O6M5IA2T4CZZ3V2RTZ3ANCNFSM4ETQZLSQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@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? |
This was a bit of a dismissive response, what's your source for this claim? |
@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. |
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. |
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. |
Sure, on save. But fair point on the screenreader. |
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:
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 |
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) |
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 |
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. |
I'm going to postpone this, since we haven't reached a consensus. |
Hi @fisker 🙂 (Same question for #7475 (comment)) |
I think we need implement #2846 first. Personally, I do single quote for JS, double quote for HTML. |
From #3503 (comment)
The text was updated successfully, but these errors were encountered: