4 ms·
Are there examples of what the formatted code looks like?
by ufo 4y ago
Are there examples of what the formatted code looks like?
- mvdan 4y agohttps://github.com/mvdan/sh/blob/master/syntax/canonical.sh https://github.com/mvdan/sh/blob/master/syntax/canonical.sh is one small example.
- usr1106 4y agoWe 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.
- erik_seaberg 4y agoI try to use line breaks instead, it only took a little getting used to for i in $(seq 100) do if expr $i % 5 > /dev/null then if expr $i % 3 > /dev/null then echo $i else echo fizz fi else if expr $i % 3 > /dev/null then echo buzz else echo fizzbuzz fi fi done
- usr1106 4y agoI did that at university around 30 years ago. I think nowadays 1TBS is much more common.
- erik_seaberg 4y agoYeah, 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.