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. It's not 100 same as go fmt but very close. You can also use 'Reformat code' command (bound to Command-Alt-L for me). Right click on your file and you will find it under 'Go tools'. 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. GoLand have commands to go fmt your file or project. 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. That number is pretty impressively high and is a good sign that. gofmt is used by a whopping 70 of packages in the wild according to a survey by go.dev. If formatting your Go code is a big pain point, then you’ll definitely be interested in leveraging this tool called gofmt. If no paths are provided, then input is taken from stdin (as with gofmt).īy default, the results are printed to stdout. Write better Golang code by using gofmt to format your code. ![]() Gofmt’d code is: easier to write: never worry about minor formatting concerns while hacking away, easier to read: when all code looks the same you need not mentally convert others’ formatting style into something you can understand. The paths can be either directories or individual files. Gofmt is a tool that automatically formats Go source code. 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |