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. 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. 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. If no paths are provided, then input is taken from stdin (as with gofmt).īy default, the results are printed to stdout. The paths can be either directories or individual files. 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. go install /x/tools/cmd/goimportslatest In addition to fixing imports, goimports also formats your code in the same style as gofmt so it can be used as a replacement for your editor's gofmt-on-save hook. When you work in GoLand, your code is formatted by the IDE’s own formatter. Overview Command goimports updates your Go import lines, adding missing ones and removing unreferenced ones. More example pairs can be found in the _fixtures directory.įirst, install the tool: go get -u /segmentio/golines Download GoLand 2021.3 EAP 3 gofmt on save enabled by default. 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |