Skip to content

Commit 280255a

Browse files
authored
various: add golangci-lint, fix issues (tailscale#7905)
This adds an initial and intentionally minimal configuration for golang-ci, fixes the issues reported, and adds a GitHub Action to check new pull requests against this linter configuration. Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I8f38fbc315836a19a094d0d3e986758b9313f163
1 parent ff1b35e commit 280255a

File tree

34 files changed

+529
-269
lines changed

34 files changed

+529
-269
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: golangci-lint
2+
on:
3+
# For now, only lint pull requests, not the main branches.
4+
pull_request:
5+
6+
# TODO(andrew): enable for main branch after an initial waiting period.
7+
#push:
8+
# branches:
9+
# - main
10+
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: read
15+
pull-requests: read
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
golangci:
23+
name: lint
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
28+
- uses: actions/setup-go@v3
29+
with:
30+
go-version-file: go.mod
31+
cache: false
32+
33+
- name: golangci-lint
34+
# Note: this is the 'v3' tag as of 2023-04-17
35+
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
36+
with:
37+
version: v1.52.2
38+
39+
# Show only new issues if it's a pull request.
40+
only-new-issues: true

.golangci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
linters:
2+
# Don't enable any linters by default; just the ones that we explicitly
3+
# enable in the list below.
4+
disable-all: true
5+
enable:
6+
- gofmt
7+
- goimports
8+
- misspell
9+
10+
# Configuration for how we run golangci-lint
11+
run:
12+
timeout: 5m
13+
14+
issues:
15+
# Excluding configuration per-path, per-linter, per-text and per-source
16+
exclude-rules:
17+
# These are forks of an upstream package and thus are exempt from stylistic
18+
# changes that would make pulling in upstream changes harder.
19+
- path: tempfork/.*\.go
20+
text: "File is not `gofmt`-ed with `-s` `-r 'interface{} -> any'`"
21+
- path: util/singleflight/.*\.go
22+
text: "File is not `gofmt`-ed with `-s` `-r 'interface{} -> any'`"
23+
24+
# Per-linter settings are contained in this top-level key
25+
linters-settings:
26+
gofmt:
27+
rewrite-rules:
28+
- pattern: 'interface{}'
29+
replacement: 'any'
30+
31+
goimports:
32+
33+
misspell:

atomicfile/atomicfile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestDoesNotOverwriteIrregularFiles(t *testing.T) {
3030
}
3131

3232
// The least troublesome thing to make that is not a file is a unix socket.
33-
// Making a null device sadly requries root.
33+
// Making a null device sadly requires root.
3434
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: path, Net: "unix"})
3535
if err != nil {
3636
t.Fatal(err)

client/tailscale/acl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func (c *Client) ValidateACLJSON(ctx context.Context, source, dest string) (test
436436
}
437437
}()
438438

439-
tests := []ACLTest{ACLTest{User: source, Allow: []string{dest}}}
439+
tests := []ACLTest{{User: source, Allow: []string{dest}}}
440440
postData, err := json.Marshal(tests)
441441
if err != nil {
442442
return nil, err

client/tailscale/dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (c *Client) dnsGETRequest(ctx context.Context, endpoint string) ([]byte, er
6363
return b, nil
6464
}
6565

66-
func (c *Client) dnsPOSTRequest(ctx context.Context, endpoint string, postData interface{}) ([]byte, error) {
66+
func (c *Client) dnsPOSTRequest(ctx context.Context, endpoint string, postData any) ([]byte, error) {
6767
path := fmt.Sprintf("%s/api/v2/tailnet/%s/dns/%s", c.baseURL(), c.tailnet, endpoint)
6868
data, err := json.Marshal(&postData)
6969
if err != nil {

cmd/pgproxy/pgproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (p *proxy) serve(sessionID int64, c net.Conn) error {
272272
}
273273
if buf[0] != 'S' {
274274
p.errors.Add("upstream-bad-protocol", 1)
275-
return fmt.Errorf("upstream didn't acknowldge start-ssl, said %q", buf[0])
275+
return fmt.Errorf("upstream didn't acknowledge start-ssl, said %q", buf[0])
276276
}
277277
tlsConf := &tls.Config{
278278
ServerName: p.upstreamHost,

cmd/tsconnect/wasm/wasm_js.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646
var ControlURL = ipn.DefaultControlURL
4747

4848
func main() {
49-
js.Global().Set("newIPN", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
49+
js.Global().Set("newIPN", js.FuncOf(func(this js.Value, args []js.Value) any {
5050
if len(args) != 1 {
5151
log.Fatal("Usage: newIPN(config)")
5252
return nil
@@ -146,7 +146,7 @@ func newIPN(jsConfig js.Value) map[string]any {
146146
}
147147

148148
return map[string]any{
149-
"run": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
149+
"run": js.FuncOf(func(this js.Value, args []js.Value) any {
150150
if len(args) != 1 {
151151
log.Fatal(`Usage: run({
152152
notifyState(state: int): void,
@@ -159,23 +159,23 @@ func newIPN(jsConfig js.Value) map[string]any {
159159
jsIPN.run(args[0])
160160
return nil
161161
}),
162-
"login": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
162+
"login": js.FuncOf(func(this js.Value, args []js.Value) any {
163163
if len(args) != 0 {
164164
log.Printf("Usage: login()")
165165
return nil
166166
}
167167
jsIPN.login()
168168
return nil
169169
}),
170-
"logout": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
170+
"logout": js.FuncOf(func(this js.Value, args []js.Value) any {
171171
if len(args) != 0 {
172172
log.Printf("Usage: logout()")
173173
return nil
174174
}
175175
jsIPN.logout()
176176
return nil
177177
}),
178-
"ssh": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
178+
"ssh": js.FuncOf(func(this js.Value, args []js.Value) any {
179179
if len(args) != 3 {
180180
log.Printf("Usage: ssh(hostname, userName, termConfig)")
181181
return nil
@@ -185,7 +185,7 @@ func newIPN(jsConfig js.Value) map[string]any {
185185
args[1].String(),
186186
args[2])
187187
}),
188-
"fetch": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
188+
"fetch": js.FuncOf(func(this js.Value, args []js.Value) any {
189189
if len(args) != 1 {
190190
log.Printf("Usage: fetch(url)")
191191
return nil
@@ -334,10 +334,10 @@ func (i *jsIPN) ssh(host, username string, termConfig js.Value) map[string]any {
334334
go jsSSHSession.Run()
335335

336336
return map[string]any{
337-
"close": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
337+
"close": js.FuncOf(func(this js.Value, args []js.Value) any {
338338
return jsSSHSession.Close() != nil
339339
}),
340-
"resize": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
340+
"resize": js.FuncOf(func(this js.Value, args []js.Value) any {
341341
rows := args[0].Int()
342342
cols := args[1].Int()
343343
return jsSSHSession.Resize(rows, cols) != nil
@@ -426,7 +426,7 @@ func (s *jsSSHSession) Run() {
426426
session.Stdout = termWriter{writeFn}
427427
session.Stderr = termWriter{writeFn}
428428

429-
setReadFn.Invoke(js.FuncOf(func(this js.Value, args []js.Value) interface{} {
429+
setReadFn.Invoke(js.FuncOf(func(this js.Value, args []js.Value) any {
430430
input := args[0].String()
431431
_, err := stdin.Write([]byte(input))
432432
if err != nil {
@@ -496,7 +496,7 @@ func (i *jsIPN) fetch(url string) js.Value {
496496
return map[string]any{
497497
"status": res.StatusCode,
498498
"statusText": res.Status,
499-
"text": js.FuncOf(func(this js.Value, args []js.Value) interface{} {
499+
"text": js.FuncOf(func(this js.Value, args []js.Value) any {
500500
return makePromise(func() (any, error) {
501501
defer res.Body.Close()
502502
buf := new(bytes.Buffer)
@@ -602,7 +602,7 @@ func generateHostname() string {
602602
// f is run on a goroutine and its return value is used to resolve the promise
603603
// (or reject it if an error is returned).
604604
func makePromise(f func() (any, error)) js.Value {
605-
handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
605+
handler := js.FuncOf(func(this js.Value, args []js.Value) any {
606606
resolve := args[0]
607607
reject := args[1]
608608
go func() {

control/controlbase/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ type maxMsgBuffer [maxMessageSize]byte
398398

399399
// bufPool holds the temporary buffers for Conn.Read & Write.
400400
var bufPool = &sync.Pool{
401-
New: func() interface{} {
401+
New: func() any {
402402
return new(maxMsgBuffer)
403403
},
404404
}

0 commit comments

Comments
 (0)