From 297b3d6fa438c6953c5a032c7d6ae2f2c6bd4eb1 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Fri, 18 Jun 2021 09:22:55 -0700 Subject: [PATCH] staticcheck.conf: turn off noisy lint errors Signed-off-by: David Crawshaw --- cmd/tailscale/cli/file.go | 1 - ipn/ipnlocal/local.go | 4 ---- ipn/ipnserver/server.go | 2 -- ipn/localapi/localapi.go | 2 +- logtail/filch/filch.go | 1 - net/dns/manager.go | 2 -- net/dns/nm.go | 2 -- net/dns/resolved.go | 2 -- net/portmapper/portmapper.go | 2 -- portlist/portlist_windows.go | 2 +- staticcheck.conf | 17 +++++++++++++++++ syncs/locked_test.go | 2 -- syncs/watchdog.go | 2 +- tstest/integration/vms/vms_test.go | 2 -- tstest/natlab/natlab.go | 3 --- types/key/key.go | 2 -- 16 files changed, 20 insertions(+), 28 deletions(-) create mode 100644 staticcheck.conf diff --git a/cmd/tailscale/cli/file.go b/cmd/tailscale/cli/file.go index bc54e4d81..7a66612fa 100644 --- a/cmd/tailscale/cli/file.go +++ b/cmd/tailscale/cli/file.go @@ -74,7 +74,6 @@ func runCp(ctx context.Context, args []string) error { return runCpTargets(ctx, args) } if len(args) < 2 { - //lint:ignore ST1005 no sorry need that colon at the end return errors.New("usage: tailscale file cp :") } files, target := args[:len(args)-1], args[len(args)-1] diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 37cd42934..92507b022 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -2711,7 +2711,6 @@ func (b *LocalBackend) CheckIPForwarding() error { return nil } if isBSD(runtime.GOOS) { - //lint:ignore ST1005 output to users as is return fmt.Errorf("Subnet routing and exit nodes only work with additional manual configuration on %v, and is not currently officially supported.", runtime.GOOS) } @@ -2728,16 +2727,13 @@ func (b *LocalBackend) CheckIPForwarding() error { for _, key := range keys { bs, err := exec.Command("sysctl", "-n", key).Output() if err != nil { - //lint:ignore ST1005 output to users as is return fmt.Errorf("couldn't check %s (%v).\nSubnet routes won't work without IP forwarding.", key, err) } on, err := strconv.ParseBool(string(bytes.TrimSpace(bs))) if err != nil { - //lint:ignore ST1005 output to users as is return fmt.Errorf("couldn't parse %s (%v).\nSubnet routes won't work without IP forwarding.", key, err) } if !on { - //lint:ignore ST1005 output to users as is return fmt.Errorf("%s is disabled. Subnet routes won't work.", key) } } diff --git a/ipn/ipnserver/server.go b/ipn/ipnserver/server.go index e67e9d8ac..e9bdfaad1 100644 --- a/ipn/ipnserver/server.go +++ b/ipn/ipnserver/server.go @@ -397,12 +397,10 @@ func (s *server) checkConnIdentityLocked(ci connIdentity) error { break } if ci.UserID != active.UserID { - //lint:ignore ST1005 we want to capitalize Tailscale here return inUseOtherUserError{fmt.Errorf("Tailscale already in use by %s, pid %d", active.User.Username, active.Pid)} } } if su := s.serverModeUser; su != nil && ci.UserID != su.Uid { - //lint:ignore ST1005 we want to capitalize Tailscale here return inUseOtherUserError{fmt.Errorf("Tailscale already in use by %s", su.Username)} } return nil diff --git a/ipn/localapi/localapi.go b/ipn/localapi/localapi.go index 00006384a..c9a5ed029 100644 --- a/ipn/localapi/localapi.go +++ b/ipn/localapi/localapi.go @@ -411,7 +411,7 @@ var dialPeerTransportOnce struct { func getDialPeerTransport(b *ipnlocal.LocalBackend) *http.Transport { dialPeerTransportOnce.Do(func() { t := http.DefaultTransport.(*http.Transport).Clone() - t.Dial = nil //lint:ignore SA1019 yes I know I'm setting it to nil defensively + t.Dial = nil dialer := net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, diff --git a/logtail/filch/filch.go b/logtail/filch/filch.go index fbb4c44f7..07d9b6203 100644 --- a/logtail/filch/filch.go +++ b/logtail/filch/filch.go @@ -15,7 +15,6 @@ import ( "sync" ) -//lint:ignore U1000 work around false positive: https://github.com/dominikh/go-tools/issues/983 var stderrFD = 2 // a variable for testing type Options struct { diff --git a/net/dns/manager.go b/net/dns/manager.go index db34475c7..85d87c7bd 100644 --- a/net/dns/manager.go +++ b/net/dns/manager.go @@ -20,8 +20,6 @@ import ( // the lint exception is necessary and on others it is not, // and plain ignore complains if the exception is unnecessary. -//lint:file-ignore U1000 reconfigTimeout is used on some platforms but not others - // reconfigTimeout is the time interval within which Manager.{Up,Down} should complete. // // This is particularly useful because certain conditions can cause indefinite hangs diff --git a/net/dns/nm.go b/net/dns/nm.go index 5ba3130b7..6130afaa1 100644 --- a/net/dns/nm.go +++ b/net/dns/nm.go @@ -4,8 +4,6 @@ // +build linux -//lint:file-ignore U1000 refactoring, temporarily unused code. - package dns import ( diff --git a/net/dns/resolved.go b/net/dns/resolved.go index 5f8d39903..0b1503320 100644 --- a/net/dns/resolved.go +++ b/net/dns/resolved.go @@ -4,8 +4,6 @@ // +build linux -//lint:file-ignore U1000 refactoring, temporarily unused code. - package dns import ( diff --git a/net/portmapper/portmapper.go b/net/portmapper/portmapper.go index 19a2931d6..3424b075f 100644 --- a/net/portmapper/portmapper.go +++ b/net/portmapper/portmapper.go @@ -577,8 +577,6 @@ func pcpAnnounceRequest(myIP netaddr.IP) []byte { return pkt } -//lint:ignore U1000 moved this code from netcheck's old PCP probing; will be needed when we add PCP mapping - // pcpMapRequest generates a PCP packet with a MAP opcode. func pcpMapRequest(myIP netaddr.IP, mapToLocalPort int, delete bool) []byte { const udpProtoNumber = 17 diff --git a/portlist/portlist_windows.go b/portlist/portlist_windows.go index 8a7791357..4c2578bba 100644 --- a/portlist/portlist_windows.go +++ b/portlist/portlist_windows.go @@ -23,7 +23,7 @@ func listPorts() (List, error) { } func addProcesses(pl []Port) ([]Port, error) { - //lint:ignore SA1019 OpenCurrentProcessToken instead of GetCurrentProcessToken, + // OpenCurrentProcessToken instead of GetCurrentProcessToken, // as GetCurrentProcessToken only works on Windows 8+. tok, err := windows.OpenCurrentProcessToken() if err != nil { diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 000000000..7e701562b --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1,17 @@ +# Full list: https://staticcheck.io/docs/checks +checks = [ + "SA*", "-SA1019", "-SA2001", # SA* are mostly legit code errors + + # S1?? are "code simplifications" which we consider unnecessary + + # ST1??? are stylistic issues, some of which are generally accepted + # In general, if it's listed in + # https://github.com/golang/go/wiki/CodeReviewComments, then it + # may be an acceptable check. + + # TODO(crawshaw): enable when we have docs? "ST1000", # missing package docs + "ST1001", # discourage dot imports + + "QF1004", # Use `strings.ReplaceAll` instead of `strings.Replace` with `n == 1` + "QF1006", # Lift if+break into loop condition +] diff --git a/syncs/locked_test.go b/syncs/locked_test.go index 32b9b64e0..cb11f15f8 100644 --- a/syncs/locked_test.go +++ b/syncs/locked_test.go @@ -4,8 +4,6 @@ // +build go1.13,!go1.16 -//lint:file-ignore SA2001 the empty critical sections are part of triggering different internal mutex states - package syncs import ( diff --git a/syncs/watchdog.go b/syncs/watchdog.go index 36dcb0758..ba5f0816b 100644 --- a/syncs/watchdog.go +++ b/syncs/watchdog.go @@ -52,7 +52,7 @@ func Watch(ctx context.Context, mu sync.Locker, tick, max time.Duration) chan ti go func() { start := time.Now() mu.Lock() - mu.Unlock() //lint:ignore SA2001 ignore the empty critical section + mu.Unlock() elapsed := time.Since(start) if elapsed > max { elapsed = max diff --git a/tstest/integration/vms/vms_test.go b/tstest/integration/vms/vms_test.go index 69e38b697..099200212 100644 --- a/tstest/integration/vms/vms_test.go +++ b/tstest/integration/vms/vms_test.go @@ -803,12 +803,10 @@ func TestDeriveBindhost(t *testing.T) { t.Log(deriveBindhost(t)) } -//lint:ignore U1000 Xe: used when debugging the virtual machines type nopWriteCloser struct { io.Writer } -//lint:ignore U1000 Xe: used when debugging the virtual machines func (nwc nopWriteCloser) Close() error { return nil } const metaDataTemplate = `instance-id: {{.ID}} diff --git a/tstest/natlab/natlab.go b/tstest/natlab/natlab.go index d818f98e1..7354e52ea 100644 --- a/tstest/natlab/natlab.go +++ b/tstest/natlab/natlab.go @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//lint:file-ignore U1000 in development -//lint:file-ignore S1000 in development - // Package natlab lets us simulate different types of networks all // in-memory without running VMs or requiring root, etc. Despite the // name, it does more than just NATs. But NATs are the most diff --git a/types/key/key.go b/types/key/key.go index 7928c1437..890d3fea4 100644 --- a/types/key/key.go +++ b/types/key/key.go @@ -85,8 +85,6 @@ func (k Private) Public() Public { func (k Private) SharedSecret(pub Public) (ss [32]byte) { apk := (*[32]byte)(&pub) ask := (*[32]byte)(&k) - //lint:ignore SA1019 Code copied from wireguard-go, we aim for - //minimal changes from it. curve25519.ScalarMult(&ss, ask, apk) return ss }