Skip to content

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

@sivchari

Description

@sivchari

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.

Metadata

Metadata

Assignees

Labels

FeatureRequestIssues asking for a new feature that does not need a proposal.ProposalToolsThis label describes issues relating to any tools in the x/tools repository.help wanted

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions