Skip to content

Add linter wastedassign#1651

Merged
ldez merged 8 commits into
golangci:masterfrom
sanposhiho:wastedassign
Feb 21, 2021
Merged

Add linter wastedassign#1651
ldez merged 8 commits into
golangci:masterfrom
sanposhiho:wastedassign

Conversation

@sanposhiho
Copy link
Copy Markdown
Member

@sanposhiho sanposhiho commented Jan 13, 2021

closes #1492

Hi :D

Add wastedassign

wastedassign finds wasted assignment statements

found the value ...

  • reassigned, but never used afterward
  • reassigned, but reassigned without using the value
func f() int {
	a := 0 
        b := 0
        fmt.Print(a)
        fmt.Print(b)
        a = 1  // This reassignment is wasted, because never used afterwards. Wastedassign find this 

        b = 1  // This reassignment is wasted, because reassigned without use this value. Wastedassign find this 
        b = 2
        fmt.Print(b)
        
	return 1 + 2
}

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented Jan 13, 2021

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 13, 2021

CLA assistant check
All committers have signed the CLA.

@ldez ldez added the linter: new Support new linter label Jan 13, 2021
@ldez
Copy link
Copy Markdown
Member

ldez commented Jan 15, 2021

Hello @sanposhiho,

could you explain why you created a fork of golang.org/x/tools (https://github.com/sanposhiho/tools) ?

I see your change:

https://github.com/sanposhiho/tools/blob/da3530a453b58298252f9d97b5419d0fc231f00b/go/analysis/passes/buildssa/buildssa.go#L51

mode := ssa.BuilderMode(ssa.NaiveForm)

https://github.com/golang/tools/blob/e0d201561e39aeaab8136532f2bbe17ae1ef24ff/go/analysis/passes/buildssa/buildssa.go#L49-L51

	// Some Analyzers may need GlobalDebug, in which case we'll have
	// to set it globally, but let's wait till we need it.
	mode := ssa.BuilderMode(0)

It seems, when I read the comment, that a PR on that point on the repo https://github.com/golang/tools will be welcome.

I pay attention to this point because it can impact golangci-lint's performance because this lib is at the heart of golangci-lint's performance optimizations.

@sanposhiho
Copy link
Copy Markdown
Member Author

sanposhiho commented Jan 16, 2021

Hi @ldez!

could you explain why you created a fork of golang.org/x/tools

I use the mode ssa.NaiveForm, because without this mode, the process called "lifting" replaces some store process with ssa.Value and can't track the use of variables.

It seems, when I read the comment, that a PR on that point on the repo https://github.com/golang/tools will be welcome.
I pay attention to this point because it can impact golangci-lint's performance because this lib is at the heart of golangci-lint's performance optimizations.

OK, I'll create PR on https://github.com/golang/tools

@ldez ldez added the waiting for: contributor feedback Requires additional feedback label Feb 20, 2021
@sanposhiho
Copy link
Copy Markdown
Member Author

sanposhiho commented Feb 21, 2021

Hi team.
I'm sorry it took me so long to reply.

I removed the dependency of wastedassign on sanposhiho/tools, because it seemed to take a while for the proposal to go/tools to be supported.

I pay attention to this point because it can impact golangci-lint's performance because this lib is at the heart of golangci-lint's performance optimizations.

So, This concern has been addressed now.

Comment thread go.mod Outdated
@SVilgelm
Copy link
Copy Markdown
Member

it would be great if you can use golang.org/x/tools v0.1.0 instead of v0.0.0-20200918232735-d647fc253266, just to be consistent with golangci-lint

Copy link
Copy Markdown
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanposhiho
Copy link
Copy Markdown
Member Author

@ldez @SVilgelm
Thanks for reviews, fixed them

@ldez ldez removed the waiting for: contributor feedback Requires additional feedback label Feb 21, 2021
Comment thread pkg/lint/lintersdb/manager.go
change an order

Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
Copy link
Copy Markdown
Member

@SVilgelm SVilgelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you

Copy link
Copy Markdown
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ldez ldez merged commit 012559c into golangci:master Feb 21, 2021
@golangci-automator
Copy link
Copy Markdown

Hey, @sanposhiho — we just merged your PR to golangci-lint! 🔥🚀

golangci-lint is built by awesome people like you. Let us say “thanks”: we just invited you to join the GolangCI organization on GitHub.
This will add you to our team of maintainers. Accept the invite by visiting this link.

By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.
More information about contributing is here.

Thanks again!

@ldez ldez added this to the v1.38 milestone Mar 6, 2024
@stefanvanburen
Copy link
Copy Markdown

I'm curious about the difference between wastedassign (https://golangci-lint.run/docs/linters/configuration/#wastedassign) and ineffassign (https://golangci-lint.run/docs/linters/configuration/#ineffassign); this was asked upstream in wastedassign but there hasn't been an answer in 2 years.

Checking an analyzer run, wastedassign is one of the highest time usage behind building, so it's tempting to disable it in favor of ineffeassign.

INFO [linters_context/goanalysis] analyzers took 21m45.544450121s with top 10 stages: buildir: 3m0.931518922s, wastedassign: 1m11.074647138s, gosec: 27.541418458s,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linter: new Support new linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for wastedassign

5 participants