News for hackers. Stuff that matters.
Re:Prettier $20k Bounty was Claimed by sltkr on Monday November 27, 2023 @01:04PM (#38435733)
This is often useful, but JavaScript specifically has the annoying property that newlines can be semantically meaningful.

For example, if someone changes:

    function isUserBanned(username) {
      return db.findUserByName(username)?.banned;
    }
To:

    function isUserBanned(username) {
      return
          db.findUserByName(username)?.banned;
    }
you want to see that diff because the second version always returns undefined. If you ignore whitespace changes entirely, it becomes possible for people to sneak in bugs intentionally or unintentionally.
Re:Prettier $20k Bounty was Claimed by blauditore on Monday November 27, 2023 @03:21PM (#38437691)
That's technically true, but extrememly rare to cause real problems (short of bad intent). It reminds me of people/teams enforcing braces on single-line ifs, because one might add another line someday, forget to add braces, and break the logic. Even when it happens, there should still be tests that catch this.
Re:Prettier $20k Bounty was Claimed by Shish2k on Monday November 27, 2023 @04:49PM (#38438887)
On the one hand, yes, there should be tests. On the other, `goto fail;` :P

Also, adding braces from the start means that adding one new line of code is a one-line patch, instead of a four-line one - I do that for the same reason that I always put trailing commas on my array definitions

Re:Prettier $20k Bounty was Claimed by blauditore on Tuesday November 28, 2023 @09:46AM (#38446279)
> one new line of code is a one-line patch

On the flipside, having three trivial early-return ifs at the beginning of a function will become 9 lines long with braces instead of 6 (or just 3, when doing single-line ifs). Very often, such cases never expand to multiple lines in the future.

Re:Prettier $20k Bounty was Claimed by HALtheWise on Monday November 27, 2023 @02:20PM (#38436888)
How much does prettier formatting help here for practical cases? In particular, if the autoformatter allowed that second example with the indentation on the last line, I'd treat that as an autoformatter bug.
Re:Prettier $20k Bounty was Claimed by tharkun__ on Monday November 27, 2023 @01:22PM (#38436018)
Enforce semicolons.
Re:Prettier $20k Bounty was Claimed by chris_wot on Monday November 27, 2023 @01:29PM (#38436122)
gawd and this is why the semicolon debate wasn't just bike shedding.