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

Add linter wastedassign #1651

Merged
merged 8 commits into from
Feb 21, 2021
Merged

Add linter wastedassign #1651

merged 8 commits into from
Feb 21, 2021

Conversation

sanposhiho
Copy link
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

boring-cyborg bot commented Jan 13, 2021

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

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
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
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 feedback required Requires additional feedback label Feb 20, 2021
@sanposhiho
Copy link
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.

go.mod Outdated Show resolved Hide resolved
@SVilgelm
Copy link
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
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
Member Author

@ldez @SVilgelm
Thanks for reviews, fixed them

@ldez ldez removed the feedback required Requires additional feedback label Feb 21, 2021
pkg/lint/lintersdb/manager.go Outdated Show resolved Hide resolved
change an order

Co-authored-by: Ludovic Fernandez <[email protected]>
Copy link
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
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

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
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
4 participants