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: keep inline comments inside test clauses in place #1019

Open
Freed-Wu opened this issue Jul 17, 2023 · 1 comment
Open

syntax: keep inline comments inside test clauses in place #1019

Freed-Wu opened this issue Jul 17, 2023 · 1 comment

Comments

@Freed-Wu
Copy link

if [[ $- != *i* && # . ./main.sh
	$- != *c* # sh -c '. ./main.sh'
	]]; then
	echo $-
fi

will be formatted to

if [[ $- != *i* &&
	$- != *c* ]] \
	; then # . ./main.sh
	# sh -c '. ./main.sh'
	echo $-
fi

I don't like the formatted code. I want $- != *i* means this script is run by . ./main.sh, $- != *c* means sh -c '. ./main.sh'. so I hope to keep the comment on the same line as the code. How to avoid this behavior?

@mvdan
Copy link
Owner

mvdan commented Jul 22, 2023

The formatter tries to keep comments where they are on a best-effort basis. This is probably an edge case that we should improve, although I admit it's the first time I ever see it, so it doesn't seem high priority. Patches with tests are always welcome, as long as you don't break the other test cases :)

@mvdan mvdan changed the title [question] keep the comment on the same line as the code syntax: keep inline comments inside test clauses in place Jul 22, 2023
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

No branches or pull requests

2 participants