To turn this behavior off, run with -no-reformat-tags. In addition to shortening long lines, the tool also aligns struct tag keys see the associated before and after examples in the _fixtures directory. If you want to reformat these too, run with the -no-ignore-generated flag. An explicit formatter can be set via the -base-formatter flag.īy default, the tool will not format any files that look like they’re generated. To enable this feature anyway, run with the -shorten-comments flag.īy default, the tool will use goimports as the base formatter (if found), otherwise it will revert to gofmt. There are also ways to enable Go’s formatter gofmt in the settings (you can read about them here), but users regularly asked us to make this option more discoverable or enable it by default. When you work in GoLand, your code is formatted by the IDE’s own formatter. golines includes some basic logic for shortening single-line (i.e., //-prefixed) comments, but this is turned off by default since the quality isn’t great. Download GoLand 2021.3 EAP 3 gofmt on save enabled by default. Shortening long comment lines is harder than shortening code because comments can have arbitrary structure and format. Running the tool with the -dry-run flag will show pretty, git-style diffs via an embedded Python script. The latter can be changed via the -m and -t flags respectively. Run golines -help to see all available flags and settings.īy default, the tool tries to shorten lines that are longer than 100 columns and assumes that 1 tab = 4 columns. Some other options are described in the sections below. To overwrite the existing files in place, use the -w flag. Unfortunately, the lack of support for doc. The rule that any span of indented or blank lines in a doc comment is rendered as a code block dates to the earliest days of Go. If no paths are provided, then input is taken from stdin (as with gofmt).īy default, the results are printed to stdout. Gofmt also inserts a blank line before and after each code block, distinguishing the code block clearly from the surrounding paragraph text. The paths can be either directories or individual files. More example pairs can be found in the _fixtures directory.įirst, install the tool: go get -u /segmentio/golines See this before and after view of a file with very long lines. More background and technical details are available in this blog post. We built golines to give go developers the option to automatically shorten long lines, like the one above, according to their preferences.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |