From 9da60a9dc5835937a210f982296d892257efe9f8 Mon Sep 17 00:00:00 2001 From: Zach <3724288+zedkipp@users.noreply.github.com> Date: Tue, 21 Oct 2025 21:10:47 +0000 Subject: [PATCH] chore: migrate from tenv linter to usetesting linter (#20401) The tenv linter is deprecated in favor of usetesting which offers a superset of lint checks. This message is seen when running `make lint` ``` [nix-shell:~/src/coder]$ make lint WARN The linter 'tenv' is deprecated (since v1.64.0) due to: Duplicate feature in another linter. Replaced by usetesting. ``` This change swaps out the deprecated tenv linter for the usetesting linter, and configures it for linting parity. https://github.com/coder/coder/issues/20398 --- .golangci.yaml | 12 +++++++++++- coderd/util/tz/tz_test.go | 5 +---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index aeebaf47e2..f03007f81e 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -169,6 +169,16 @@ linters-settings: - name: var-declaration - name: var-naming - name: waitgroup-by-value + usetesting: + # Only os-setenv is enabled because we migrated to usetesting from another linter that + # only covered os-setenv. + os-setenv: true + os-create-temp: false + os-mkdir-temp: false + os-temp-dir: false + os-chdir: false + context-background: false + context-todo: false # irrelevant as of Go v1.22: https://go.dev/blog/loopvar-preview govet: @@ -252,7 +262,6 @@ linters: # - wastedassign - staticcheck - - tenv # In Go, it's possible for a package to test it's internal functionality # without testing any exported functions. This is enabled to promote # decomposing a package before testing it's internals. A function caller @@ -265,4 +274,5 @@ linters: - typecheck - unconvert - unused + - usetesting - dupl diff --git a/coderd/util/tz/tz_test.go b/coderd/util/tz/tz_test.go index a0e7971bd7..57d2d660ec 100644 --- a/coderd/util/tz/tz_test.go +++ b/coderd/util/tz/tz_test.go @@ -35,12 +35,9 @@ func Test_TimezoneIANA(t *testing.T) { // This test can be flaky on some Windows runners :( t.Skip("This test is flaky under Windows.") } - oldEnv, found := os.LookupEnv("TZ") + _, found := os.LookupEnv("TZ") if found { require.NoError(t, os.Unsetenv("TZ")) - t.Cleanup(func() { - _ = os.Setenv("TZ", oldEnv) - }) } zone, err := tz.TimezoneIANA()