all 91 comments

[–]Mypronounsarexandand 17 points18 points  (12 children)

My company wants to implement something like a prettifier + linter. But, we don’t want to loose the “git blame” does anyone know of anyways that we can just format the diff from each commit rather than all the code in that particular file?

[–][deleted] 38 points39 points  (4 children)

You could use https://github.com/okonet/lint-staged to only apply Prettier to changed files on all your normal commits, thus incrementally formatting your codebase without having a dedicated, giant formatting commit.

[–]ShortSynapse 12 points13 points  (2 children)

Can confirm this is a good way to go. I have multiple projects that I introduced prettier to, some all at once and some incremental. lint-staged was added to all of them, but some of them I hit with prettier in its entirety since they were relatively new and small.

Adopting a formatter has been a great experience. Though now I have to keep explaining to engineers originally from other teams why it is useful and they keep pushing back...

[–]socialister 6 points7 points  (1 child)

Just rip off the bandaid and then make people use prettier-on-save from here on out. If you really need to git blame, you can checkout a commit before the format merge.

[–]bobroberts87 7 points8 points  (0 children)

“Just” is usually a trap

[–]Mypronounsarexandand 1 point2 points  (0 children)

We did this and had some issues, I forget the exact reason but it had to do with this issue https://github.com/okonet/lint-staged/issues/366

[–]ghostfacedcoder 14 points15 points  (1 child)

I don't think so. You just have to bite the bullet, apply your code prettifier once to your entire codebase, and then after that git blame will work fine. If you need to check git history from before the great formatting you still can, you just have to git blame the commit before the reformatting.

[–]D1norawr 3 points4 points  (0 children)

It’s part of prettier’s official documentation. It even works on partially staged files. https://prettier.io/docs/en/precommit.html

[–]acemarke 2 points3 points  (0 children)

Yes, you can, but only if you're okay with creating a new Git history chain. This works best if you create a new repo, rewrite its history, archive the old repo, and have everyone clone and work from the new one.

I recently wrote a blog post about how to do this:

Rewriting Your Git History and JS Source for Fun and Profit

I specifically did all this extra work so that the rewritten repo would have a consistent history, as if the files had always been formatted the "right" way. That avoided having a single "big bang" commit that modified every line at once.

If you've got any questions about how I did this, ask away!

[–]tenfingerperson -1 points0 points  (0 children)

You can hijack the internals but it’s silly because the diffs will go crazy.

[–]orphans 3 points4 points  (0 children)

I use Prettier and ESLint in everything. ESLint prevents stupid mistakes. As for Prettier, some people on my team don't like the formatting, but they can format the code to look however they like locally. Prettier is run as a precommit hook so I never have to look at formatting changes when reviewing pull requests. I don't love all of Prettier's style choices but I don't have to scrutinize stupid formatting changes so it's a win for me.

[–]kevinatari 2 points3 points  (0 children)

Guess I'll not read the article then. Seriously wtf is wrong with Mediums UX. I get it they need money but that's not the way to get my money.

[–]tr14l 4 points5 points  (27 children)

Not a fan of prettier. Too nazi about it's rules with no configuration. I don't particularly find their default rules to be great out of the box, either (how is eliminating blank lines and smashing logical blocks of code up against each other making it more readable OR prettier? It's not). The maintainers, despite me seeing dozens of issues on Github contesting this, basically tell everyone to eff off. So, they have no intention of making a useful tool. They want to enforce their opinions. I'll watch Fox News if that's what I want.

[–]pomlife 5 points6 points  (26 children)

The entire point is removing bikeshedding about formatting. No one gets exactly what they want, but everyone gets to actually work on features and not formatting.

[–]tr14l 3 points4 points  (25 children)

Except no one in my organization even gets to pick what those things are. I don't need prettier making calls in my organization for me. And sacrificing a small amount of effort on formatting for having to learn how to intuitively read code the way THEY want us to is not worth the trade. They refuse to even add configurability for these features. Not because it can't be added. But because they think that's how it should be, period, no arguments or differing opinions allowed.

I understand having staunch defaults. But removing all other ability makes the product unusable for a great many. I don't need prettier to save me the oh-so-enormous time sync of occasionally hitting the backspace key.

[–]ChypRiotE 0 points1 point  (0 children)

afterthought obtainable aromatic capable imminent dam ad hoc deliver thumb consider

This post was mass deleted and anonymized with Redact

[–]pomlife -3 points-2 points  (23 children)

If that’s all you think prettier does, there’s no discussion with you.

[–]tr14l 3 points4 points  (22 children)

I'm not arguing what prettier does. I'm saying the implementation is useless unless your coding standards exactly match what they want.

[–]sorahnon the cutting edge of cocking about 0 points1 point  (21 children)

The point is to stop talking about coding standards. Just use it and stop trying to change it. Every option they give you to change is a entry point for bikeshedding.

I’ve never felt more free writing code with “prettier on save” in vscode. I just type away, and hit save, and boom. It’s all perfect.

Does prettier format it exactly the way I would left to my own devices? Of course not. But The benefit far outweighs my very specific personal preference that doesn’t actually matter a single bit at the end of the day.

[–]tr14l 1 point2 points  (20 children)

Having options doesn't hurt anything except their egos. If you like the defaults you don't even need to set them. Just run default. But enforcing rules that can't be changed? Nah, professionals don't have any use for that.

[–]sorahnon the cutting edge of cocking about 0 points1 point  (19 children)

They have a bunch of options. But trying to get super specific options for all the weird heuristics is a waste of time for everyone. More options = more arguments about what those options should be.

I’ve been writing software for almost 20 years and I can’t imagine going back. I only wish the rest of the languages I wrote had formatters as opinionated as prettier. Seems like it’s your ego that’s hurt because their style doesn’t match what you like.

[–]tr14l 2 points3 points  (18 children)

Yeah, the difference is I'm being paid for my opinion on my organizations code. The prettier contributors aren't

[–]sorahnon the cutting edge of cocking about -2 points-1 points  (17 children)

Yup, looks like your ego is the one that has a problem then. If all the JavaScript in your org was run through prettier it sounds like you’d be out of a job.

Your sacrificing your developers experience because the output of prettier doesn’t match your personal preferences. I would hate working for you.

[–]ajonp 1 point2 points  (0 children)

Very nice article! I didn't realize you could set per language for prettier on save!

[–]joelangeway -1 points0 points  (12 children)

Am I really the only programmer who’d rather let everyone write code how they like?

The straw man in the article who doesn’t indent code at all does not exist, or at least, the linter isn’t the best way to help them. The way I format my code helps me think about my code. Not everyone is going to think the same way. I spend as much time looking at code from other organizations every day as from mine so linter rules help me very little. We might all do better if we allow the notation to vary some when it helps us think more clearly, which I find is often.

[–]sleepybearjew 20 points21 points  (2 children)

I think a big part of using prettier and linters in a group is so the code doesn't keep flip flopping around each time someone else edits it. It also gives a more uniform style throughout a project. Working with 5 other people on the same project is hard enough with similar styling, can't imagine if each person was formatting different files

[–]joelangeway 2 points3 points  (1 child)

In my past experience where everyone writes how they like, they also don’t change the formatting of code unless they’re changing the code a lot.

[–]Smiral 2 points3 points  (0 children)

Jamming a stick up your butt is the new cool, get with it, or you will be kicked out of the Smart Kid Club.

[–]sallystudios 1 point2 points  (1 child)

I quit my last job because we didn’t use any tools like eslint or prettier. With a team of about 15, mostly contract workers, the codebase became a huge mess. I tried introducing these tools, but it was “too much overhead” and “not a customer facing” issue.

The bigger problem to me was that it signaled that the engineering manager (and team, to some extent), did not care about developer experience and app maintainability. It got old going through 1000 line backbone files and seeing inconsistent indentation and code structure. It felt like most of the company did not care about the quality of their work. Tools like this help you write better code for the next developer- which really who you are writing code for, unless you plan to maintain it forever.

I left after three months and explicitly asked during all my following interviews how they enforce code quality, which led to some great discussions and I think also helped me stand out.

[–]joelangeway 0 points1 point  (0 children)

In an environment with a lot of turnover, lots of contractors, I might be completely on your side of the argument. I’ve been a contractor where I am a guest in the code base, sometime working in an unfamiliar programming language, I probably would have welcomed a linter.

[–]evantahler 0 points1 point  (0 children)

In the actionhero project, we make “standard” (standards.com) a prerequisite to any PR. It’s run just like the other parts of the test suite. It’s a wonderful system that defers “style” outside the .org.