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

Reflow long comment lines which don't end with a period #59

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

shivansh
Copy link
Contributor

@shivansh shivansh commented Mar 19, 2022

$ cat x.go
package main

// Unlike the above comment block, only the current line in this comment block has length greater than the
// target maximum line length
// but since the previous line doesn't end with a period, it should be reflown with this line
// despite both the lines being shorter than the target maximum line length.

$ golines --shorten-comments x.go
package main

// Unlike the above comment block, only the current line in this comment block has length greater
// than the
// target maximum line length
// but since the previous line doesn't end with a period, it should be reflown with this line
// despite both the lines being shorter than the target maximum line length.

The modified behavior is to reflow long comment lines which don't end
with a period with the consecutive comment lines, irrespective of the
latter being long or not.

$ golines --shorten-comments x.go
package main

// Unlike the above comment block, only the current line in this comment block has length greater
// than the target maximum line length but since the previous line doesn't end with a period, it
// should be reflown with this line despite both the lines being shorter than the target maximum
// line length.

@shivansh shivansh changed the title Reflow long lines which don't end with period Reflow long lines which don't end with a period Mar 19, 2022
@shivansh shivansh force-pushed the shivansh/comment-reflow branch from c4a54ae to fc397bd Compare March 19, 2022 08:48
@shivansh
Copy link
Contributor Author

Though the comment formatting is still in an experimental stage, I believe this PR will improve it to some extent. However, if this is accepted, a note should be added in README for users to be aware of the usage of period (.) to avoid unexpected behavior.
For example -

$ cat x.go 
package main

// - this is a long comment this is a long comment this is a long comment this is a long comment this is a long comment.
// - this is a short comment

$ golines --shorten-comments x.go
package main

// - this is a long comment this is a long comment this is a long comment this is a long comment
// this is a long comment - this is a short comment

The above unexpected behavior can be avoided by adding a . at the end of first bullet:

$ cat x.go 
package main

// - this is a long comment this is a long comment this is a long comment this is a long comment this is a long comment.
// - this is a short comment

$ golines --shorten-comments x.go
package main

// - this is a long comment this is a long comment this is a long comment this is a long comment
// this is a long comment.
// - this is a short comment

@shivansh shivansh changed the title Reflow long lines which don't end with a period Reflow long comment lines which don't end with a period Mar 19, 2022
	$ cat x.go
	package main

	// Unlike the above comment block, only the current line in this comment block has length greater than the
	// target maximum line length
	// but since the previous line doesn't end with a period, it should be reflown with this line
	// despite both the lines being shorter than the target maximum line length.

	$ golines --shorten-comments x.go
	package main

	// Unlike the above comment block, only the current line in this comment block has length greater
	// than the
	// target maximum line length
	// but since the previous line doesn't end with a period, it should be reflown with this line
	// despite both the lines being shorter than the target maximum line length.

The modified behavior is to reflow long comment lines which don't end
with a period with the consecutive comment lines, irrespective of the
latter being long or not.

	$ golines --shorten-comments x.go
	package main

	// Unlike the above comment block, only the current line in this comment block has length greater
	// than the target maximum line length but since the previous line doesn't end with a period, it
	// should be reflown with this line despite both the lines being shorter than the target maximum
	// line length.
@shivansh shivansh force-pushed the shivansh/comment-reflow branch from fc397bd to d922ed2 Compare March 19, 2022 09:48
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 this pull request may close these issues.

1 participant