new()
Reports cases where a pointer can be created directly from an expression using new() in Go 1.26.
Instead of declaring a temporary variable just to take its address, you can pass the value or function result directly to new. This removes boilerplate code, keeps related logic in one place, and makes pointer initialization easier to read.
예:
age := calculateAge(birthDate)
user := &User{
Name: "Alice",
Age: &age,
}
Here, the code creates a temporary variable only to take its address.
To simplify this, use the Replace with 'new()' quick-fix. 빠른 수정을 적용한 후:
user := &User{
Name: "Alice",
Age: new(calculateAge(birthDate)),
}
This form avoids unnecessary temporary variables.