Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: comments before case are incorrectly indented #917

Closed
zx8 opened this issue Sep 21, 2022 · 2 comments · Fixed by #952
Closed

syntax: comments before case are incorrectly indented #917

zx8 opened this issue Sep 21, 2022 · 2 comments · Fixed by #952

Comments

@zx8
Copy link

zx8 commented Sep 21, 2022

$ 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
@mvdan
Copy link
Owner

mvdan commented Sep 22, 2022

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

@mvdan mvdan changed the title Comments before variable case conditionals are incorrectly indented syntax: comments before case are incorrectly indented Sep 22, 2022
@mvdan
Copy link
Owner

mvdan commented Dec 2, 2022

Another very similar case below minimized from #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 added a commit that referenced this issue Dec 3, 2022
We weren't doing that when a case clause item used quoted strings,
due to the `p.tok == _LitWord` condition that shouldn't be there.
Add tests, docs, and also prevent SingleLine from producing bad syntax
when printing the new test.

Fixes #917.
@mvdan mvdan closed this as completed in #952 Dec 4, 2022
mvdan added a commit that referenced this issue Dec 4, 2022
We weren't doing that when a case clause item used quoted strings,
due to the `p.tok == _LitWord` condition that shouldn't be there.
Add tests, docs, and also prevent SingleLine from producing bad syntax
when printing the new test.

Fixes #917.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants