1- [ ![ Circle CI ] ( https://circleci .com/gh/ segmentio/golines. svg?style=svg&circle-token=b1d01d8b035ef0aa71ccd183580586a80cd85271 )] ( https://circleci .com/gh/ segmentio/golines )
1+ [ ![ golines test ] ( https://github .com/segmentio/golines/actions/workflows/go.yml/badge. svg )] ( https://github .com/segmentio/golines/actions/workflows/go.yml )
22[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/segmentio/golines )] ( https://goreportcard.com/report/github.com/segmentio/golines )
33[ ![ GoDoc] ( https://godoc.org/github.com/segmentio/golines?status.svg )] ( https://godoc.org/github.com/segmentio/golines )
4- [ ![ Coverage] ( https://img.shields.io/badge/Go%20Coverage-84%25-brightgreen.svg?longCache=true&style=flat )] ( https://gocover.io/github.com/segmentio/golines?version=1.13.x )
54
65# golines
76
8- Golines is a golang formatter that shortens long lines, in addition to all
7+ Golines is a Go code formatter that shortens long lines, in addition to all
98of the formatting fixes done by [ ` gofmt ` ] ( https://golang.org/cmd/gofmt/ ) .
109
1110## Motivation
1211
13- The standard golang formatting tools (` gofmt ` , ` goimports ` , etc.) are great, but
14- [ deliberately don't shorten long lines] ( https://github.com/golang/go/issues/11915 ) ; instead, this
15- is an activity left to developers.
12+ The standard Go formatting tools (` gofmt ` , ` goimports ` , etc.) are great, but
13+ [ deliberately don't shorten long lines] ( https://github.com/golang/go/issues/11915 ) ;
14+ instead, this is an activity left to developers.
1615
1716While there are different tastes when it comes to line lengths in go, we've generally found
1817that very long lines are more difficult to read than their shortened alternatives. As an example:
@@ -33,7 +32,7 @@ myMap := map[string]string{
3332}
3433```
3534
36- We built ` golines ` to give go developers the option to automatically shorten long lines, like
35+ We built ` golines ` to give Go developers the option to automatically shorten long lines, like
3736the one above, according to their preferences.
3837
3938More background and technical details are available in
@@ -47,27 +46,29 @@ view of a file with very long lines. More example pairs can be found in the
4746
4847## Version support
4948
50- The latest version of ` golines ` requires golang 1.18 or newer due to generics-related dependencies.
51- If you need to use ` golines ` with an older version of go, install the tool from the ` v0.9.0 `
52- release.
49+ Newer releases of ` golines ` require at least Go 1.18 due to generics-related dependencies.
50+ However, the [ minimum version] ( https://go.dev/ref/mod#go-mod-file-go ) in [ ` go.mod ` ] ( ./go.mod )
51+ should be considered the minimum required version of Go for any given version
52+ of ` golines. ` If you need to use ` golines ` with an older version of go, install
53+ the tool from the ` v0.9.0 ` release.
5354
5455## Usage
5556
56- First, install the tool. If you're using golang 1.18 or newer, run:
57+ First, install the tool. If you're using Go 1.21 or newer, run:
5758
58- ```
59+ ``` text
5960go install github.com/segmentio/golines@latest
6061```
6162
62- Otherwise, for older golang versions, run:
63+ Otherwise, for older Go versions, run:
6364
64- ```
65+ ``` text
6566go install github.com/segmentio/[email protected] 6667```
6768
6869Then, run:
6970
70- ```
71+ ``` text
7172golines [paths to format]
7273```
7374
@@ -79,10 +80,10 @@ files in place, use the `-w` flag.
7980
8081## Options
8182
82- Some other options are described in the sections below. Run ` golines --help ` to see
83- all available flags and settings.
83+ Some other options are described in the sections below. Run ` golines --help ` to
84+ see all available flags and settings.
8485
85- #### Line length settings
86+ ### Line length settings
8687
8788By default, the tool tries to shorten lines that are longer than 100 columns
8889and assumes that 1 tab = 4 columns. The latter can be changed via the
@@ -102,15 +103,15 @@ with the `--shorten-comments` flag.
102103
103104#### Custom formatters
104105
105- By default, the tool will use [ ` goimports ` ] ( https://godoc.org/golang.org/x/tools/cmd/goimports ) as
106- the base formatter (if found), otherwise it will revert to ` gofmt ` . An explicit formatter can be
107- set via the ` --base-formatter ` flag; the command provided here should accept its input via
108- ` stdin ` and write its output to ` stdout ` .
106+ By default, the tool will use [ ` goimports ` ] ( https://godoc.org/golang.org/x/tools/cmd/goimports )
107+ as the base formatter (if found), otherwise it will revert to ` gofmt ` . An explicit
108+ formatter can be set via the ` --base-formatter ` flag; the command provided here
109+ should accept its input via ` stdin ` and write its output to ` stdout ` .
109110
110111#### Generated files
111112
112- By default, the tool will not format any files that look like they're generated. If you
113- want to reformat these too, run with the ` --no-ignore-generated ` flag.
113+ By default, the tool will not format any files that look like they're generated.
114+ If you want to reformat these too, run with the ` --no-ignore-generated ` flag.
114115
115116#### Chained method splitting
116117
@@ -140,8 +141,8 @@ myObj.Method(arg1, arg2, arg3).
140141 AThirdMethod (arg1, arg2)
141142```
142143
143- The original behavior can be used by running the tool with the ` --no-chain-split-dots `
144- flag.
144+ The original behavior can be used by running the tool with the
145+ ` --no-chain-split-dots ` flag.
145146
146147#### Struct tag reformatting
147148
@@ -167,9 +168,8 @@ let g:go_fmt_options = {
1671681 . Install the [ Run on Save] ( https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave ) extension
1681692 . Go into the VSCode settings menu, scroll down to the section for the "Run on Save"
169170 extension, click the "Edit in settings.json" link
170- 3 . Set the ` emeraldwalk.runonsave ` key as follows (adding other flags to the ` golines `
171- command as desired):
172-
171+ 3 . Set the ` emeraldwalk.runonsave ` key as follows
172+ (adding other flags to the ` golines ` command as desired):
173173```
174174 "emeraldwalk.runonsave": {
175175 "commands": [
@@ -181,18 +181,18 @@ let g:go_fmt_options = {
181181 }
182182```
183183
184- 4 . Save the settings and restart VSCode
184+ 1 . Save the settings and restart VSCode
185185
186186### Goland
187187
1881881 . Go into the Goland settings and click "Tools" -> "File Watchers" then click the plus to create a new file watcher
1891892 . Set the following properties and confirm by clicking OK:
190- - __ Name:__ ` golines `
191- - __ File type:__ ` Go files `
192- - __ Scope:__ ` Project Files `
193- - __ Program:__ ` golines `
194- - __ Arguments:__ ` $FilePath$ -w `
195- - __ Output paths to refresh:__ ` $FilePath$ `
190+ - __ Name:__ ` golines `
191+ - __ File type:__ ` Go files `
192+ - __ Scope:__ ` Project Files `
193+ - __ Program:__ ` golines `
194+ - __ Arguments:__ ` $FilePath$ -w `
195+ - __ Output paths to refresh:__ ` $FilePath$ `
1961963 . Activate your newly created file watcher in the Goland settings under "Tools" -> "Actions on save"
197197
198198### Others
0 commit comments