sh
sh copied to clipboard
syntax: comments before `case` are incorrectly indented
$ shfmt --version
v3.3.1
Notice # baz is indented 2 extra spaces, when it shouldn't be.
Actual
case foo in
# bar
"$bar") ;;
# baz
"$baz") ;;
esac
Expected
case foo in
# bar
"$bar") ;;
# baz
"$baz") ;;
esac
Thanks, this looks like a valid bug. The printer should probably be a bit smarter.
Another very similar case below minimized from https://github.com/mvdan/sh/discussions/950; I think they are all the same bug:
$ shfmt -version
v3.6.0-0.dev.0.20221125121205-436da662a80b
$ cat f.sh
case x in
# doesn't move
c)
foo
;;
# does move!
"")
foo
;;
esac
$ shfmt f.sh
case x in
# doesn't move
c)
foo
;;
# does move!
"")
foo
;;
esac