Are you maintaining dead code?

July 12, 2023

I’m taking a break from the Go spec today to talk about a new tool I just discovered, that saved me a bunch of work.

One of the clients I’m working with has a rather old codebase, filled with a bunch of retired features. It was a laborious task to go through all the thousands of files in the project to see which functions and types were no longer being used.

I tried using golangci-lint’s unused linter, but it only detects unexported symbols that aren’t used. I wanted something to detect exported symbols, as this isn’t a library that’s imported by anything else.

That’s when someone turned me on to a very recent addition to the repo: a command to report dead code in Go programs

It’s just what I needed!

And here’s the result:

I would love to see this new tool incorporated into golangci-lint. Maybe that’ll come later. But even without that, it’s a great tool. Check it out, and see if you can’t remove some dead code from your project!

Share this