cfmt is a tool to wrap Go comments over a certain length to a new line.
go get -u github.com/alexkohler/cfmt
Note: cfmt requires gofmt.
Similar to other Go static anaylsis tools (such as golint, go vet), cfmt can be invoked with one or more filenames, directories, or packages named by its import path. cfmt also supports the ...
wildcard.
cfmt [flags] files/directories/packages
- -m - Maximum comment length before cfmt should insert a line break. (Default 80)
- -w - Writes changes to file. By default,
cfmt
will only print the changes it will make, but will not modify the input files.
cfmt
will wrap to a new line or join an existing line as appropriate. See the following before/afters of running cfmt -m=100
:
Before
// I am a long comment that is over 100 characters long. I should probably wrap to a new line.
After
// I am a long comment that is over 100 characters long. I should probably wrap
// to a new line.
Before
// I am a long comment that is over 100 characters long. I should probably wrap below to the
// rest of the comment.
After
// I am a long comment that is over 100 characters long. I should probably wrap
// below to the rest of the comment.
Before
//I am a long comment that starts without a space and is over 100 characters long. When I wrap, I should still start without a space
After
//I am a long comment that starts without a space and is over 100 characters
//long. When I wrap, I should still start without a space
cfmt
ignores block (/* */
) comments and "grouped" comments over a length of 10 (i.e. 10+ consecutive lines starting with //
).
Pull requests welcome!
If you've enjoyed cfmt, take a look at my other static anaylsis tools!