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
Introduce standard.js compatibility flag #5723
Conversation
I fixed the tests Also, one notable project that needs to run |
Just curious: what stats could support this claim? I've done a small personal research recently to figure out if no semicolons are really common these days in JS. My subjective conclusion was ‘no’ as the majority of popular repos I've looked into do use semicolons. I have semicolons in most JS/TS projects too, not only because because they are a part of the language and because they are default in Prettier, but also because things like Full disclaimer: I'm not a big fan of Given that Prettier is not just for JS and Anyway, this is just my subjective opinion which is not a blocker for anything the majority of maintainers decide. I'm not a maintainer myself – just hanging around in the repo now and then 😉 Please don't consider my words as criticism of your work @sheerun – I'm just trying to contribute to Prettier core just as you do 😉 🙌 |
Thank you for response. First of all let me kindly dismiss your argument "look too ugly to me.". As you noticed later it's subjective matter plus provided cases are very rare in real code. Prettier states about itself that it's "opinionated code formatter", it's no different. Standard is just a name. I'm not here to argue which style is better but provide solution for these developers who find standard's syntax better. I've read this article you provided and it focuses on something that in my long experience is never a problem. It states problem but immediately provides solution (semicolons when line starts with Again I don't want to argue about which style is better so let's focus on more objective reasons.
I've downloaded 1000 most popular npm packages dependent upon and 154 of them use standard while 125 of them use prettier, which is not ultimate stat but I hope it shows standard isn't a niche and your statement that "majority of popular repos I've looked into do use semicolons" might be true but is not relevant. Also in my experience many projects use prettier but also use
Actually most of current prettier options apply only to javascript.
Not sure what's the reasoning you're referring to, or what may be suboptimal. What's sure that many project exist with codebases in standard style, a well as many developers who would like to start projects in standard style and they would also love to use prettier for nice whitespace. This PR allows all of them for easy migration to prettier without having whitespace removed after every function name. The same way, dont' consider my words criticism of your likings. I realise many prefer semicolons and I don't intend to argue about it. I hope prettier realises this is not matter of one team fighting the other but rather respecting and acknowledging each other. |
Thanks @sheerun for your work on this idea. But I have a major concern that it mixes several things together:
I would really favor keeping these items in separate options. This would really help people using "semistandard", for example. |
(babel parser) discovered through standard.js compat proposal in prettier#5723 Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl>
(babel parser) discovered through standard.js compat proposal in prettier#5723 Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl> Co-authored-by: Joseph Frazier <1212jtraceur@gmail.com> Co-authored-by: Rafael Hengles <rafael@hengles.net>
(babel parser) discovered through standard.js compat proposal in prettier#5723 Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl> Co-authored-by: Joseph Frazier <1212jtraceur@gmail.com> Co-authored-by: Rafael Hengles <rafael@hengles.net>
"semistandard" is much less popular than standard (7 packages of top 1000 use it). Ultimately this decision is up to prettier, what I care only about it that I can use prettier to format according to standard rules. It doesn't really matter to me if I use one flag or 5. I would need official stance of @prettier in form of "if you change this and that, we'll merge this PR" |
So … I might be wrong, but here goes: I've been under the impression that people use standard because it's easy to use, helpful and ends many code style debates (no configuration). Not because it uses the exact code style people have been looking for (no semicolons, spaces in some places). If so … does it really matter if Prettier's code style is slightly different? |
corresponding to eslint generator-star-spacing option tested with and without space-before-function-paren enabled as needed for consistency with standard & semistandard based on proposal in prettier#5723 Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl> Co-authored-by: Joseph Frazier <1212jtraceur@gmail.com> Co-authored-by: Rafael Hengles <rafael@hengles.net> Co-authored-by: Ika <ikatyang@gmail.com> Co-authored-by: Lucas Azzola <derflatulator@gmail.com>
corresponding to eslint yield-star-spacing option tested with and without the following options enabled: * generator-star-spacing * space-before-function-paren as needed for consistency with standard & semistandard based on proposal in prettier#5723 Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl> Co-authored-by: Joseph Frazier <1212jtraceur@gmail.com> Co-authored-by: Rafael Hengles <rafael@hengles.net> Co-authored-by: Ika <ikatyang@gmail.com> Co-authored-by: Lucas Azzola <derflatulator@gmail.com>
as originally proposed in prettier#5723 Co-authored-by: Adam Stankiewicz <sheerun@sher.pl> Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
to achieve the functionality proposed in prettier#5723 (though not in a single option flag)
I integrated this proposal into the I think we still need some kind of a higher-level tool like An alternative solution for the improved formatting capabilities may be some kind of plugin support. |
@brodybits Have you considered using ESLint directly instead of through standard, with eslint-config-standard + eslint-config-prettier? |
No semicolons is main reason, but it's more than that: Imagine you've created your library in 2015. Because you don't like semicolons you've chosen
I could do the same for |
I used to be an adamant "no semicolons person", but bit the bullet when Prettier came out (initially the |
Yes. I personally like to use "semistandard", which is standard with semicolons, through configuration of eslint. But prettier seems to be missing some formatting capabilities that are proposed here:
👍 |
PR for the spacing is here: #3903. It doesn’t add a space before the |
Maybe prettier could introduce
|
PR #3903 seems to miss some other cases that are covered by this PR,
I think it would also be nice if PR #3903 could be rebased or updated with the latest changes from
Nice idea. But there are quite a few (semi)standard semantic rules for eslint that seem to be outside the scope of prettier. |
In accordance with Prettier's options philosophy, there exist >400 votes against adding |
It's not like there are thousands of formatting standards, there is prettier, standard, and maybe semistandard. What @gaearon said was probably a reference to huge number of eslint config options. |
Any ideas for moving forward with the formatting improvements? Anything better than forking? |
prettier is similar to standard / semistandard / airbnb / google that all are collections of formatting rules, they don't allow you to choose exact formatting options the same way prettier doesn't want to prettier is at the same something more: it allows for precise whitespace formatting, previous tools were very limited at this. many projects that use other formatting standard like Please realise that most options prettier introduced so far or that are requested, were because people want to configure this particular option but because they want standard and semistandard formatting:
So in a way it was possible for prettier to have single |
@brodybits How do you motivate space before function paren, generator star spacing and yield star spacing? |
These are rules used by standard whitespace formatting It doesn't need motivation as it's arbitrary decision made by This is why this PR doesn't try to introduce these options one by one, it actually follows your "resisting adding configuration" rule more than any single option you'd add (though |
But why? Why can't existing projects change? Just trying to understand all the details. |
While changing formatting standard with few developers is fairly easy, it is a big challenge for big projects with many pending pull requests to merge which would cause many conflicts and coordination and disorder of whole team for some time. I don't like how discussion goes because everyone tells me to prove that standard is better or why somebody would not like to switch to prettier. It is not better or worse, it's different. If prettier was black-hair only hairdresser I suggested to support blonde hair I wouldn't need to explain how popular blonde hair is, hear that it's "ugly", or why blonde people just won't color their hair black, because it's so easy. |
I don't want to argue anymore so I'd like to ask maintainers: what is the solution you propose? |
I think you will get many merge conflicts with open PRs even with a |
I’m wondering if we should make a docs page with some information from people who have done this, since the docs don’t have much information on adding Prettier to an existing project. |
@sheerun We're not asking you to prove why one is better than the other. We just really hate supporting multiple code styles. And in order to keep a single code style, we ask since day one "what's the most common way people write this code by hand" for every piece of syntax. That's also what drives our decisions to add new options or not: we won't add new options unless we believe it will "unblock" lots of people to start using Prettier. That's why you're seeing "pushback" in this thread, we really don't like adding options. I'd like to remind that while we do want new users and try to support them, we won't do that by supporting other code styles and that's why I think Prettier is not for everyone. We support this tool that formats code automatically as consistent as we can (which is good for a number of reasons), and the users just need to let go of their previous formatting preferences. If they can't do that, maybe Prettier is not for them, but that's fine. |
Could you as compromise agree to accept PR with |
At the risk of going slightly off topic, I wanted to share my perspective. @lydell one thing I didn't see being discussed in this thread is the non-style related aspects of standard. I happily switched from standard to prettier, the auto formatting is great. I don't mind the specifics of each tool's styling choices, like many, I like to not have to make those decisions. The issue I quickly ran into after switching from standard to prettier is how prettier only formats the code, it doesn't lint against very common issues (aka stuff in eslint:recommended, things like unused variables). I was used to So now I have a few options (back to having to make decisions with linters). Use Ideally, I just want a single tool to do both formatting and linting, but maybe I'm in the minority? I guess it's simply not prettier's concern to add And just for completeness sake, here's the possible scenarios I see that would solve this problem for me and hopefully many other long time standard users:
Again, apologies if this is a bit off topic. I understand the thread was more about making the interop between prettier and standard better. Especially for reasons @sheerun mentioned in this thread, where long time codebases want to benefit from prettier without having to reformat existing code. But I think there's this other overlooked dimension to the question of why people might want to combine the two tools – which is that both formatting and linting are very valuable and that convention based easy to use tools are also valuable. |
@KidkArolis Sounds like you're looking for ESLint + eslint-config-standard + eslint-config-prettier + eslint-plugin-prettier. Then you get a single tool (ESLint) that does both code quality checking and style linting (with autofix). I use this in a project at work (where we used plain standard before) and it works nicely. |
@KidkArolis the fact that Prettier does not dive into the code semantics its actually a benefit rather than a disadvantage. It leaves you with an option to check the semantics with ESLint, TypeScript compiler, TSLint, StyleLint, and many others. There are lots of languages that Prettier can work with, including those available through plugins. Thus, if Prettier spills over the scope of spaces and tabs, the tool will become too bulky. I see your point about standard.js caring both about the style and the semantics, this is handy indeed. However, this leaves you with a tool that is JS-only, which is somewhat too narrow these days. |
@kachkaev I think that makes sense, which is why my suggested options 1, 3 or 4 are probably better options. I'm just trying to see which one is the most viable. @lydell if you use ESLint + eslint-config-standard + eslint-config-prettier + eslint-plugin-prettier, don't the prettier rules conflict with standard rules? Or else this GH issue (about |
They don't! eslint-config-prettier disables all the conflicting ones. |
And now going really off topic.. should look into this myself, but which one is more comprehensive: eslint-config-standard or eslint-config-recommended? If I'm jumping standard ship into the prettier one, might as well reconsider which eslint set I'm using. |
If you mean the built-in |
I guess I for now I won't convince anyone from prettier to support flags that make formatting closer to standard, so for now I've released prettier-standard that uses prettierx fork instead, so anyone wants even better standard.js compatibility than prettier-standard provides, please send pull request to it. |
as reported in brodybits/prettierx#40 (this was missed by the proposal in prettier#5723) Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Mohit Singh <mohit@mohitsingh.in> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl>
in tests/standard & docs as reported in brodybits/prettierx#40 (this was missed by the proposal in prettier#5723) Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Mohit Singh <mohit@mohitsingh.in> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl>
in tests/standard & docs as reported in brodybits/prettierx#40 (this should have been part of the proposal in prettier#5723) Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Mohit Singh <mohit@mohitsingh.in> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl>
in tests/standard & docs as reported in brodybits/prettierx#40 (this should have been part of the proposal in prettier#5723) Note that this inconsistency is resolved by brodybits/prettierx#41 which is to be included in an upcoming merge. Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Mohit Singh <mohit@mohitsingh.in> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl>
in tests/standard & docs as reported in brodybits/prettierx#40 (this should have been part of the proposal in prettier#5723) Note that this inconsistency is resolved by brodybits/prettierx#41 which is to be included in an upcoming merge. Co-authored-by: Christopher J. Brody <chris.brody@gmail.com> Co-authored-by: Mohit Singh <mohit@mohitsingh.in> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl>
@lydell Have you actually tested and verified this yourself? Because it doesn't in mine and many others experiences when it comes to |
@User486375 Can you give a minimal reproduction? I have a {
"extends": ["standard", "prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
}
} and a {
"semi": false
} and I do not get any errors when linting a file containing function f() {
return 0
}
console.log(f()) So it looks to me like extending |
docs/
directory)Hello prettier,
I am the author of prettier-standard library that tries to be similar to prettier while maintaining compatibility with standard that has been present for some time before prettier. Standard is still used by many developers and its rules are preferred by many developers (equivalents of --no-semi --single-quote --jsx-single-quote like + not implemented --space-before-function-paren).
While I enjoy github stars \s prettier-standard is not a perfect solution because it needs to pass every file first through prettier and then though eslint with standard whitespace rules. This makes this process very slow. Ideally this functionality would be embedded within prettier itself so developers can just write
prettier --standard
instead ofprettier-standard
. I would gladly deprecate my package and point to new prettier version if you agreed to merge this PR.There's discussion whether introduce extra flag for inserting space before function name or anonymous function, this won't make prettier compatible with standard as there are many more nuances like spaces around generator stars. This PR introduces
--standard
flag that has single purpose: make prettier format code as such runningstandard
after it won't complain about formatting of code. I think it's good measure to not introduce many flags into prettier and at the same time satisfy people who even start to fork this project.I've gathered all whitespace-related rules of standard and added tests for each of them from straight from eslint docs (both correct ones and incorrect ones). I've also included compatibility with the way standard wants to format typescript and flow. You can verify that with this flag formatting is compatible with standard by running following commands or visually inspecting new tests:
You can find more information how to configure standard for flow & typescript on their home page.
What do you think? This could potentially be last and final flag to satisfy standard.js camp.