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
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.
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