News for hackers. Stuff that matters.
Re:Shfmt – format shell programs (like gofmt, rustfmt) by ufo on Saturday February 11, 2023 @03:20PM (#34755946)
Are there examples of what the formatted code looks like?
Re:Shfmt – format shell programs (like gofmt, rustfmt) by mvdan on Saturday February 11, 2023 @03:33PM (#34756066)
Re:Shfmt – format shell programs (like gofmt, rustfmt) by usr1106 on Saturday February 11, 2023 @04:09PM (#34756380)
We introduced it at work after the code base containing had been developed for 3 - 4 years with just manual reviews. The changes we needed to make were rather small and most of them were oversights, the code should not have looked like that in the first place. Of course your mileage might vary.

The only thing that disturbed me personally is no space before semicolon. Without having read what spec says I think the semicolon in shell is more of a command separator than a terminator. So I had always formatted it symmetrically, with space before and after like e.g. && or a pipe. shfmt did not support that so I had to adapt. Still having a tool and skipping review discussions outweighs this minor matter of taste.

Re:Shfmt – format shell programs (like gofmt, rustfmt) by erik_seaberg on Saturday February 11, 2023 @04:28PM (#34756558)
I try to use line breaks instead, it only took a little getting used to

  for x in 1 2 3
  do if [ x -eq 2 ]
     then frob x
          more_stuff
     else dont
     fi
  done
Re:Shfmt – format shell programs (like gofmt, rustfmt) by usr1106 on Saturday February 11, 2023 @04:42PM (#34756685)
I did that at university around 30 years ago. I think nowadays 1TBS is much more common.
Re:Shfmt – format shell programs (like gofmt, rustfmt) by erik_seaberg on Saturday February 11, 2023 @04:49PM (#34756754)
Yeah, I use 1TBS and cuddled elses in Scala/Java/C++, but adding a semicolon to do it with a keyword feels like arguing with the grammar.