golang/go

x/tools/go/analysis/passes/modernize: add testingsetenv analyzer

オープン

#77,735 opened on 2026/02/22

 (13 件のコメント) (4 件のリアクション) (1 人の担当者)Go (19,008 件のフォーク)batch import

Repository metrics

Stars
 (133,883 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Proposal Details

Add a new analyzer that replaces manual environment variable save/restore with t.Setenv (Go 1.17+).

// Before
defer os.Setenv("GOOS", os.Getenv("GOOS"))
os.Setenv("GOOS", f[0])

// After
t.Setenv("GOOS", f[0])

Conditions

  • Pattern: defer os.Setenv(key, os.Getenv(key)) followed by os.Setenv(key, value)
  • defer must precede os.Setenv (defer args are evaluated immediately)
  • Within test function, before any t.Parallel() call
  • Go 1.17+

Similar to testingcontext analyzer.

コントリビューターガイド