sh icon indicating copy to clipboard operation
sh copied to clipboard

syntax: comments before `case` are incorrectly indented

Open zx8 opened this issue 3 years ago • 1 comments

$ 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

zx8 avatar Sep 21 '22 11:09 zx8

Thanks, this looks like a valid bug. The printer should probably be a bit smarter.

mvdan avatar Sep 22 '22 14:09 mvdan

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

mvdan avatar Dec 02 '22 10:12 mvdan