Explorar el Código

ci: run 'go vet' in golangci-lint; fix errors in tests

Updates #cleanup

Signed-off-by: Andrew Dunham <[email protected]>
Change-Id: Ice78fc907bad24c1de749a1595e212ef2db4b8bb
Andrew Dunham hace 2 años
padre
commit
3f576fc4ca
Se han modificado 4 ficheros con 50 adiciones y 2 borrados
  1. 43 0
      .golangci.yml
  2. 3 0
      Makefile
  3. 3 1
      cmd/tailscale/cli/cli_test.go
  4. 1 1
      posture/serialnumber_macos_test.go

+ 43 - 0
.golangci.yml

@@ -6,6 +6,7 @@ linters:
     - bidichk
     - gofmt
     - goimports
+    - govet
     - misspell
     - revive
 
@@ -35,6 +36,48 @@ linters-settings:
 
   goimports:
 
+  govet:
+    # Matches what we use in corp as of 2023-12-07
+    enable:
+      - asmdecl
+      - assign
+      - atomic
+      - bools
+      - buildtag
+      - cgocall
+      - copylocks
+      - deepequalerrors
+      - errorsas
+      - framepointer
+      - httpresponse
+      - ifaceassert
+      - loopclosure
+      - lostcancel
+      - nilfunc
+      - nilness
+      - printf
+      - reflectvaluecompare
+      - shift
+      - sigchanyzer
+      - sortslice
+      - stdmethods
+      - stringintconv
+      - structtag
+      - testinggoroutine
+      - tests
+      - unmarshal
+      - unreachable
+      - unsafeptr
+      - unusedresult
+    settings:
+      printf:
+        # List of print function names to check (in addition to default)
+        funcs:
+          - github.com/tailscale/tailscale/types/logger.Discard
+          # NOTE(andrew-d): this doesn't currently work because the printf
+          # analyzer doesn't support type declarations
+          #- github.com/tailscale/tailscale/types/logger.Logf
+
   misspell:
 
   revive:

+ 3 - 0
Makefile

@@ -9,6 +9,9 @@ vet: ## Run go vet
 tidy: ## Run go mod tidy
 	./tool/go mod tidy
 
+lint: ## Run golangci-lint
+	./tool/go run github.com/golangci/golangci-lint/cmd/golangci-lint run
+
 updatedeps: ## Update depaware deps
 	# depaware (via x/tools/go/packages) shells back to "go", so make sure the "go"
 	# it finds in its $$PATH is the right one.

+ 3 - 1
cmd/tailscale/cli/cli_test.go

@@ -1328,7 +1328,9 @@ func TestParseNLArgs(t *testing.T) {
 	for _, tc := range tcs {
 		t.Run(tc.name, func(t *testing.T) {
 			keys, disablements, err := parseNLArgs(tc.input, tc.parseKeys, tc.parseDisablements)
-			if !reflect.DeepEqual(err, tc.wantErr) {
+			if (tc.wantErr == nil && err != nil) ||
+				(tc.wantErr != nil && err == nil) ||
+				(tc.wantErr != nil && err != nil && tc.wantErr.Error() != err.Error()) {
 				t.Fatalf("parseNLArgs(%v).err = %v, want %v", tc.input, err, tc.wantErr)
 			}
 

+ 1 - 1
posture/serialnumber_macos_test.go

@@ -15,7 +15,7 @@ import (
 
 func TestGetSerialNumberMac(t *testing.T) {
 	// Do not run this test on CI, it can only be ran on macOS
-	// and we currenty only use Linux runners.
+	// and we currently only use Linux runners.
 	if cibuild.On() {
 		t.Skip()
 	}