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: insert single space before and after line comment # #1031

Open
j-lakeman opened this issue Sep 9, 2023 · 3 comments
Open

syntax: insert single space before and after line comment # #1031

j-lakeman opened this issue Sep 9, 2023 · 3 comments

Comments

@j-lakeman
Copy link

I'd expect this

#!/usr/bin/env bash

true#test

to be formatted to that

#!/usr/bin/env bash

true # test

to increase readability and to be consistent to other programming languages.

@Rairden
Copy link

Rairden commented Sep 25, 2023

Yes me too. I look forward to when shfmt adds a space for commented lines.

#!/bin/bash

foo() {
#   echo 1
	#echo 2
	# echo 3
	echo 4
}

foo

true #test

I expect shfmt to turn the echo 1 and echo 2 lines to look like echo 3.
No matter what flags I run with shfmt, the output is something like this:

shfmt -d format-me.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 foo() {
-#   echo 1
+   #   echo 1
    #echo 2
    # echo 3
    echo 4

@mvdan
Copy link
Owner

mvdan commented Oct 14, 2023

shfmt heavily borrows from Go's gofmt, which has never forced a leading space in comments, and I personally think that's fine. Most people will prefer comments leading with one space, but nothing is particularly wrong about comments that don't.

For example, what about comments starting with a tab character, what should we do with them? Or what about empty comments?

@j-lakeman
Copy link
Author

Please see this:

https://chat.openai.com/share/2fa42d22-4344-485d-acab-4c9a7847ce95

I know the tool is questionable. In this case however I used it for a quick summary.

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

3 participants