Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assigned to. XXXX, but reassigned without using the value (wastedassign) #441

Open
wwcchh0123 opened this issue Nov 8, 2024 · 0 comments

Comments

@wwcchh0123
Copy link
Contributor

lint 解释

  • 该 lint 出现表示一个变量被赋值后又被重新赋值,但在此过程中没有使用其原始值。这种情况通常表明代码中可能存在冗余,或者可能是逻辑错误,因为原始值在此期间没有被实际使用。

错误用法

func main() {
    x := 10
    x = 20 // 重新赋值,但未使用原始值

    fmt.Println("x =", x) // 仅打印新值20
}

正确用法

  • 方案一:使用赋值变量
  • 方案二 :移除冗余赋值
@wwcchh0123 wwcchh0123 changed the title assigned to. 'XXXXX', but reassigned without using the value (wastedassign) assigned to. XXXXX, but reassigned without using the value (wastedassign) Nov 11, 2024
@wwcchh0123 wwcchh0123 changed the title assigned to. XXXXX, but reassigned without using the value (wastedassign) assigned to. XXXX, but reassigned without using the value (wastedassign) Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant