-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Adopt prettier for consistent formatting #811
Comments
Posted this too early going to edit description to include more detalis. |
It isnt the right thing in any way. There is ES-Beautifier that tries to do everything using the ESLint ecosystem. That's the right move. Prettier is meant to be opinionated and so it cant be easily integrated and should not be. The ESLint --fix feature is awesome, and we all should just invest some time to implement autofixes for any rules that we want, then no matter the style we will have awesome consistency prettifier and linter in one. ESLint is the right tool for such things. ESLint autofix works great here. I think the most important rule that we should implement autofix for is And everyone should use Just Prettier isn't the right tool. Tried it in last months. Both approaches - first linter than prettiefier and reversed first prettier then the linter - both not work well. ESLint is most awesome ecosystem in that community, for sure. And we should use it, everyone should use it as both Linter and Prettiefier/Beautifier/Formatter. It just need help. |
I fundamentally disagree with this. Prettier completely disregards input format and spits out in a consistent format while ESLint and tools around that attempt to preserve typed style & that is pretty much makes consistent styling impossible.
As we tried to adopt standard style we run into too many cases where ESLint was unable to fix things up.
Not in my experience there is ton of things it can not fix and there is also ton of flex in the way code can be formatted, and standard will accept. So at the end of the day we still have majority of comments in pulls about formatting, which defeats the purpose, to us anyway.
In my experience fixes actually produce awkward results in terms of formatting, my guess would be that is a reason.
You have not offered any convincing argument to support that claim, just your own opinion that ESLint is a way to go. Please try to offer more constructive input and offer some data to support claims.
I am not surprised given that prettier output does not follow stardardjs rules. By work is required I meant following @jlongster's suggestion to fork prettier to add an options for [standardjs][] rules, hopefully it would be possible to merge it back in. Can you share list of things that did not work.
It's cool that you feel that way, but saying everyone should use it is a bit too much. For flow typed projects ESLint has very little to offer other than enforcing formatting as type system deals with actual errors. And given that formatting rules are too flexible result is again, valuable engineering time is spend in discussing or comprehending code formatting. |
@Gozala We used a separate tool to do formatting in the past ( I think prettier is cool, especially if you want to always re-format code on every git check-in, but it's too aggressive for normal use. It will reformat even code that passes But I think we'll stick with eslint's
I'll also mention that the trend of each release of standard is to tighten up rules to prevent multiple ways of writing the same thing. There are many more formatting rules that will be added slowly in future releases. So issues like the ones you ran into should be caught in future releases once we tighten up those rules. |
|
@timoxley That's actually a neat solution for folks who prefer more aggressive regular formatting of their code. |
That won't work, because Prettier and Standard rules will collide. It would be great if efforts could be unified and maintainers of boths libs would agree on same code style...
I think it's very strange to hear that from creator of lib, which actually aggressively enforces rules on developer. |
I think this might be one of those things we look back at in a year and be like, why did we cling on manually formatting the code. Auto standard ftw. |
Yeap. I'm ready for this right now :D As a side information, about "love" between Standard and Prettier, I will just leave this link here facebook/create-react-app#1847, maybe someone has somthing meaningful to add. |
@ArmorDarks not a fan of your tone here, it could be mistaken as hostile; please show some moderation going forward. Thank you kindly ✨ |
@yoshuawuyts If you read my conversation with Dan by following link above, you will see that I'm adept of Standard and defend it, thus I didn't mean to be hostile. However, yeap, I was sarcastic, because both libraries enforces aggressive rules, so it sounded like very strange and vague argument against when said by creator of one of those libs. |
@ArmorDarks I'm a fan of the concept of
In an ideal world, they'd adopt all the If you or someone else wants to look into this approach in more detail, I'm open to at least reviewing the PR. |
Ah, @feross. nevermind my earlier replies. To make this happen we will need attitude to make compromises and changes from both and Standard, and Prettier communities, to unite efforts and focus on strongest points (linting with Standard and code formatting with Prettier) instead of continuing bikeshedding. I was hoping to make this happen, to help communities unite, but after pretty much aggressive replies of @gaearon against Standard here facebook/create-react-app#1847 and recently discovered regreatful issue #78 (which explains nature of @gaearon attitude toward Standard) started by @gaearon and supported by @jlongster (creator of Prettier) here #78, I have very little believe that this could happen. Not in this world, I guess. |
@ArmorDarks FWIW, I'm open to working with the Do you know if it's possible to configure |
cc @vjeux |
You can already use standard without its formatting rules by using https://www.npmjs.com/package/eslint-config-prettier, and then use prettier to format it. Users interested in this issue are mostly interested in getting the non-formatting rules. For standard using prettier by default, it's going to be hard, not because of any ill will on either sides, but because there is already a significant community behind both so changing the styles is going to force one of them to change a lot. I don't know what the answer is. If someone wants to pursue it we need to more concrete changes to evaluate it. Note that a large number of people prefer to run prettier in their editor frequently as they are coding (prettier by default is very fast, much faster than eslint, so it's very responsive), and do linting as a less frequent step. I think it makes sense to separate linting and formatting, and allow users to combine them how they want. |
Also, prettier's code wrapping (which is an integral part of why it produces good code) is always going to be a big change for the output of standard. There's no way we can make it so that our output is exactly the same as the current |
If we did this, we'd probably want to add a new
So, then users that want one canonical format could throw
The good news here is that |
Just thought I'd link to this: |
I think I'm a little confused what the goal is: do you want to take advantage of prettier's wrapping & forcing consistency on more general things (like function arguments), but still apply standard's whitespace rules? If so, that should be pretty easy: run prettier first and then Or are you all somehow wanting the output of standard to be the same as prettier, meaning it runs prettier as the last step? That seems harder because we would have to talk about all the differences and see if we can reconcile. I'm not sure I see the benefit of that since you could easily run Looks like I'm happy to continue talking about what potential integrations look like! |
Thinking out loud here... I think the goal of
// both styles are allowed by `standard`
const x = (z) => z
const y = z => z Since both styles are allowed by const x = z => z
const y = z => z But this is okay, since the rewritten code is also valid Then after running So, it seems like in an ideal world, To get to this world, I think we'd need unify our style guides so that |
I think we want (I want) standard to automformat the code (such that all
standard codebases are identical, unambiguous). Maybe that just means I
should switch to prettier.
But Feross makes a good point - standard is designed to be human writable
and indeed very pleasant to write.
Feels like we should be able to converge the two, fudamentally, I mean cant
see why we need both prettier and standard. Im sure I (and anyone) could
get used to whatever slight variations of style each lib chooses. It's more
about the question of - should code style be enforced and unambiguous or
should we leave a bit of room for human interpretation (not sure which one
is better). The goal of "human writable" is great, but maybe at conflict
with "unambiguous".
🤔
…On Thu, 13 Apr 2017 at 21:30, James Long ***@***.***> wrote:
If we did this, we'd probably want to add a new standard --format flag
I think I'm a little confused what the goal is: do you want to take
advantage of prettier's wrapping & forcing consistency on more general
things (like function arguments), but still apply standard's whitespace
rules? If so, that should be pretty easy: run prettier first and then standard
--fix. Is that what standard --format could do?
Or are you all somehow wanting the output of standard to be the same as
prettier, meaning it runs prettier as the last step? That seems harder
because we would have to talk about all the differences and see if we can
reconcile. I'm not sure I see the benefit of that since you could easily
run standard --fix *after* prettier to tweak it to get all the current
rules (like a space after function name).
Looks like prettier-standard-formatter is runs prettier first and than standard
--fix which makes sense.
I'm happy to continue talking about what potential integrations look like!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#811 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AATzWIkMPFHv9-ssY2v7ORyuGYzFuwdoks5rvoXWgaJpZM4MSpCd>
.
|
@feross I see, thanks for explaining! I'm a little worried about both of the communities having to keep in sync and making sure that any changes need to be accepted by both, etc. But I actually think most of the things we'd change are not even whitespace-related or things that standard's formatting rules care about. Usually it's a bug with how things are laid out. Although.. that might not be true. A good example is that we are thinking of changing how we output ternaries. Right now we happen to output them as standard expects, actually. But we might change that. I think we're actually very in sync already. The biggest difference is the space after function name. I'm betting that you all don't want to change that, I don't think we're going to change that on prettier... as its a pretty frequent thing in the code. Not sure what we'd do about that specific case, but concerns about not being able to change the format still stands. Is there any reason it can't be |
Agreed! I think there's a real opportunity here, given a few compromises, to prevent further fragmentation in community conventions.
This is a fair point. But I think that if we wanted, we could each do a release where we change a rule or two and then we're totally in sync. Bam. Then we can recommend There are challenges, but this seems totally doable if both projects want to make it happen.
Your description of how But, then we don't get the huge win that would come from aligning our styles. Namely that it would be easy to switch from/to the different projects, |
Awesome. I gotta run but let's keep talking! Are you all really opinionated about the space after function name? fwiw we've been referencing the airbnb style guide to inform us (as one data point) of what is a popular style, and they don't use the space there. It also seems to be preferred by most people who use it. This is probably going to be the biggest sticking point between our styles, I'm guessing. |
Also our default style is semicolons, but we just added an option to not use semicolons, so we can do |
most noticeable thing for me is that prettier expands function arguments if >1 and i believe not makes code more readable but more bad. i 'm totally okey with that tobe only when >3.
as about the space after fn name, it's acceptable to relax the rule so there won't have breaking changes. |
btw, to clarify a bit about fn args expanding, i'm okey with if line is around 80 to do the expanding in multiple lines, even if the only one arg. sorry, im on phone |
Discussed further in #927. Solving this would be a nice step towards consistency with Prettier formatting. (I did update the
I have mixed feelings about switching
I think it would be ideal to check and process the code using a series of plugins, like what can be done with eslint and what is generally done with Babel, keeping Prettier reformatting as an optional step. |
Hi.. I've been hanging out on this thread for a while and have recently been thinking more about this problem. Standard has been enourmously helpful in the last few years in all my projects. The two styles are slightly different, which is unfortunate. But standard is not just about code style, it's also about zero config experience, a really well curated set of eslint rules, less decision making. I've been wanting to get the best of both, prettier's formatting with standard's code quality checks and DX. I've just published a package https://github.com/KidkArolis/healthier that tries to help you combine the two. Hopefully it can be useful to some of you if you're ok with letting go off standard's style formatting rules. In the future, if standard somehow adopts prettier's formatter, that might be even better. But for now I will see if Healthier can fill that gap. |
So I've recently switched to The only way I can see getting that working is adding back Anyways, just wondering if anyone has gotten format on save and linting while typing working with |
You can use |
Healthier has both |
So, I think the ideal setup would be one npm module (+ one editor plugin) that gives you formatting on save and linting as you type - all with no configuration. Then use I've been using Long story short, I ended up going down a rabbit hole of inconsistencies between @KidkArolis Thanks for the awesome package, and great choice on the name 👍 Good bye |
It's a bummer that |
Same was here. But I switched around 1.5 year ago (after years of using Standard) to the @airbnb style - definitely liked it and it makes much more sense to me, cuz I always been a fan of a bit more strictness (pretty great considerations/practices and a lot lot rules). Looking from the perspective of a few years using both Airbnb+Prettier (~2y) and Standard (2y), I really think that tools like standard, xo and the others that appeared after them, isn't that great thing. It sounds and feels unnecessary stacking of tooling, APIs and deps. "Zero config". But you can have zero config with picking up basic Anyway, no bad feelings 🥇 It's probably great from someone who is junior-to-mid or just starting up until realizing he/she (or its community) need better style and quality. |
@tunnckoCore with airbnb, does airbnb code style rules not complain about prettier’s formatting? Or do you turn them off somehow? Re, “it’s probably great for someone who is junior-to-mid”, a strange way to classify this. Since so many many people and tools use standard who I wouldn’t call junior.. And I have been using standard 5+ years because of its ease of use, when you work on dozens of repos, the zero config approach shines, one dep, does it all, helps you catch the bugs, is not too strict so never complains about things that would get in the way. But admittedly, I actually never really tried airbnb, there’s just not enough time to try all the things :) |
@tunnckoCore I loved |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Not a nice bot |
I decided to do the same and move back to ESLint with Prettier + eslint-config-standard |
Just so you know recent version of prettier-standard has linting feature built-in that lints code with eslint-config-standard configuration after formatting it with prettier: |
Absolute legend @sheerun |
I am using // .eslintrc.js
module.exports = {
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module'
},
env: {
node: true
},
plugins: ['prettierx'],
extends: ['standardize', 'plugin:prettierx/standardize-bundle'],
settings: {
prettierx: {
usePrettierrc: true,
editorconfig: true
}
},
rules: {
'generator-star-spacing': [
'error',
{
before: true,
after: true,
anonymous: { before: true, after: true },
method: { before: true, after: true }
}
],
'prettierx/options': ['error', require('./.prettierrc.json')]
}
} // .prettierrc.json
{
"printWidth": 100,
"semi": false,
"singleQuote": true,
"quoteProps": "consistent",
"jsxBracketSameLine": true,
"jsxSingleQuote": true,
"endOfLine": "lf",
"spaceBeforeFunctionParen": true,
"trailingComma": "none",
"arrowParens": "avoid",
"bracketSpacing": true,
"generatorStarSpacing": true,
"yieldStarSpacing": true
} As far as I can see, it mostly adheres to standard, and a simple I have packaged it up and published it in my company's private registry, so I only need to require that package and
|
It is worth considering adding this feature for |
A different approach: #1872 . |
@feross what do you think in terms of adopting prettier ? The reason I find it appealing is because in the process of adopting standardjs (see browserhtml/browserhtml#1271) we found out that it's too permissive and does not catch variety of awkward formatting options.
I think with a help of prettier standardjs could deliver promise of "JavaScript Standard Style". Unfortunately that would require some work prettier/prettier#736 to make prettier output standardjs compatible.
The text was updated successfully, but these errors were encountered: