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

ex does not like rules including unused variables #4

Closed
mvdan opened this issue Nov 30, 2020 · 4 comments
Closed

ex does not like rules including unused variables #4

mvdan opened this issue Nov 30, 2020 · 4 comments

Comments

@mvdan
Copy link

mvdan commented Nov 30, 2020

For example, the script below could be used to simplify obtaining a map key, rewriting foo, _ := bar[idx] into foo := bar[idx]:

$ rf 'ex { var m map[string]int; var s string; x, _ := m[s] -> x := m[s] }'
ex.go:6:2: x declared but not used
ex.go:7:3: x declared but not used
ex: errors in example:
	package ipld
	func _() {
	var m map[string]int
	var s string
	{
	{x, _ := m[s] }
	{ x := m[s]}
	}
	}

This fails, because the rule snippet alone does not use the declared variable. Perhaps we should turn off such "not used" errors when loading rules, or perhaps we should add a special way to write rules to match declarations. A special way could then also match var foo, _ = bar[idx] and foo, _ = bar[idx], for example.

@mvdan
Copy link
Author

mvdan commented Nov 30, 2020

Also, how open are you to contributions and ideas? I'd like to start using rf for some backwards-incompatible API changes across repos at work, as a sort of custom go fix. I have some experience in this field via https://github.com/mvdan/gogrep, which supports rewriting entire chunks of statements, declarations, etc.

@mdempsky
Copy link
Collaborator

mdempsky commented Dec 7, 2020

I'd be fine with changing unused variables into a warning rather than an error.

@mvdan
Copy link
Author

mvdan commented Dec 7, 2020

@mdempsky thanks! Would a PR here be welcome, or is GitHub just a mirror?

@mdempsky
Copy link
Collaborator

mdempsky commented Dec 7, 2020

PR is fine.

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

2 participants