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 )
2
2
[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/segmentio/golines )] ( https://goreportcard.com/report/github.com/segmentio/golines )
3
3
[ ![ 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 )
5
4
6
5
# golines
7
6
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
9
8
of the formatting fixes done by [ ` gofmt ` ] ( https://golang.org/cmd/gofmt/ ) .
10
9
11
10
## Motivation
12
11
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.
16
15
17
16
While there are different tastes when it comes to line lengths in go, we've generally found
18
17
that very long lines are more difficult to read than their shortened alternatives. As an example:
@@ -33,7 +32,7 @@ myMap := map[string]string{
33
32
}
34
33
```
35
34
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
37
36
the one above, according to their preferences.
38
37
39
38
More 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
47
46
48
47
## Version support
49
48
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.
53
54
54
55
## Usage
55
56
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:
57
58
58
- ```
59
+ ``` text
59
60
go install github.com/segmentio/golines@latest
60
61
```
61
62
62
- Otherwise, for older golang versions, run:
63
+ Otherwise, for older Go versions, run:
63
64
64
- ```
65
+ ``` text
65
66
go install github.com/segmentio/[email protected]
66
67
```
67
68
68
69
Then, run:
69
70
70
- ```
71
+ ``` text
71
72
golines [paths to format]
72
73
```
73
74
@@ -79,10 +80,10 @@ files in place, use the `-w` flag.
79
80
80
81
## Options
81
82
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.
84
85
85
- #### Line length settings
86
+ ### Line length settings
86
87
87
88
By default, the tool tries to shorten lines that are longer than 100 columns
88
89
and assumes that 1 tab = 4 columns. The latter can be changed via the
@@ -102,15 +103,15 @@ with the `--shorten-comments` flag.
102
103
103
104
#### Custom formatters
104
105
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 ` .
109
110
110
111
#### Generated files
111
112
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.
114
115
115
116
#### Chained method splitting
116
117
@@ -140,8 +141,8 @@ myObj.Method(arg1, arg2, arg3).
140
141
AThirdMethod (arg1, arg2)
141
142
```
142
143
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.
145
146
146
147
#### Struct tag reformatting
147
148
@@ -167,9 +168,8 @@ let g:go_fmt_options = {
167
168
1 . Install the [ Run on Save] ( https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave ) extension
168
169
2 . Go into the VSCode settings menu, scroll down to the section for the "Run on Save"
169
170
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):
173
173
```
174
174
"emeraldwalk.runonsave": {
175
175
"commands": [
@@ -181,18 +181,18 @@ let g:go_fmt_options = {
181
181
}
182
182
```
183
183
184
- 4 . Save the settings and restart VSCode
184
+ 1 . Save the settings and restart VSCode
185
185
186
186
### Goland
187
187
188
188
1 . Go into the Goland settings and click "Tools" -> "File Watchers" then click the plus to create a new file watcher
189
189
2 . 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$ `
196
196
3 . Activate your newly created file watcher in the Goland settings under "Tools" -> "Actions on save"
197
197
198
198
### Others
0 commit comments